I need to pass the function as a component argument. How can I do this? I have function "handlerFunction" that I want to pass to the child component SearchComponent.
ProfilePage.js
export const ProfilePage = () => {
const [docID, setDocID] = useState(null)
const handlerFunction = (id) => {
setDocID(id)
}
return (
<div className="ProfilePage">
profile page {uid}
<SearchComponent token={access} handler={handlerFunction}/>
</div>
)
}
SearchComponent.js
export const SearchComponent = (token, handler) => {
return (
<a onClick={() => handler(doc["id"])}>Button</a
)
}
My code is not working cuz of "Uncaught TypeError: handler is not a function". Help me please)