Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
How callback functions works?

I'm using ReactSuperSelect library for my react app and I've found one moment, that I can't understand.

<ReactSuperSelect datasource={data} onChange={(item) => console.log(item)} />

This console.log will return something like this: [{id: 'id of selected elem', name: 'name of selected elem'}].

But when I'm trying to do the same thing in any other place (I mean not in the scope of ReactSuperSelect component), I'm getting SyntheticBaseEvents object.

So, as I understand, onChange event in ReactSuperSelect is something like a callback function, that returns some value and I can use this value in higher scope (correct me if I'm wrong).

My question is: how can I emulate the same behavior in my components? For example: <MyComponent onClick={(clickedElement) => console.log(clickedElement)} and get the result like this {id: 'id', name: 'anyName'}.

P.S. I know about clickedElement.target.value, but I wanna get custom response instead of SyntheticBaseEvents

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Answer for comments from coglialoro

I have to create such components:

import React from 'react';

const MyComponent = ({ onClick }) => {
  const myItem = {
    id: 'id',
    name: 'anyname',
  };
  return <button onClick={() => onClick(myItem)}>Click</button>;
};

export default MyComponent;
import React from 'react';
import MyComponent from './MyComponent';
import './style.css';

export default function App() {
  return (
    <div>
      <MyComponent onClick={(clickedElement) => console.log(clickedElement)} />
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!