score:5
Since Search
is a component, the onClick
event handler has to be passed onto the element inside it. onClick
is as any other prop on a component and has no default meaning.
const Search = ({onClick}) => {
return (
<Container onClick={onClick}>
<Icon icon={faSearch} />
</Container>
)
}
score:2
you should add that onClick props in Search component. You are not utilising that props. If you want on click on let say on icon element then you should do something like this.
const Search = (props) => {
return (
<Container>
<Icon icon={faSearch} onClick={props.onClick} />
</Container>
)
}
If you want it to add on Container element then you should do like this.
const Search = (props) => {
return (
<Container onClick={props.onClick}>
<Icon icon={faSearch} />
</Container>
)
}
score:2
This is because the custom Search
component does not implement an onClick
callback prop. Extending Search
with the following should resolve the issue:
/* Add props argument */
const Search = (props) => {
return (
{/* Add onClick prop to span, and pass through supplied onClick prop */}
<Container onClick={props.onClick}>
<Icon icon={faSearch} />
</Container>
)
}
Source: stackoverflow.com
Related Query
- onClick not working on my React component
- onClick event not working within nested React / Next.js component
- onClick event in React parent component is not working
- onClick in button tag is not working in react component
- React component onClick handler not working
- onClick not working in React functional component
- OnClick event in React not working in child component
- React Component Function not working onClick button
- Button onClick is not working in my react component
- lodash debounce in React functional component not working
- onclick function is not working in react native application
- onClick not working React js
- React Form Component onSubmit Handler Not Working
- React Context API not working from custom NPM component library
- Applying className/onClick/onChange not working on Custom React Component
- Dynamic import in react not working when trying to import a component in another directory
- Select is not working onClick IconComponent(dropdown-arrow) in react material ui
- span does not firing OnClick inside list react child component
- React onClick event handler not working using Next.js
- ScrollTop not working in React Component or inspector
- Style of React component is not working on Heroku
- Serving REACT component using express is not working (just html file is rendered)
- Programmatically redirecting inside child component in React JS is not working
- onbeforeunload not working inside react component
- React onClick not working in any of my browsers, but for colleagues it does
- React OnClick for item not working
- MDL Component Not working with React
- onClick not working inside the pop up opened via React portals
- React Component to render children conditionally not working as I want it to
- Importing SVG as React component not working with Next.js
More Query from same tag
- How do I access the contents of a .tsv file with React and papa-parse?
- React .createClass() scroll to ref: scrollIntoView not a function
- fetch API not sending data via post
- Cant setup react router
- How can I re-render one component from another component in React?
- How to iterate through an array inside an array.map function?
- React Error - No routes matched location "/"
- Set background image in ionic 5
- Is it possible to use the touch ripple effect of MUI on a div?
- 404 error when trying to list envelopes in react sample app
- Where is ESLint cache stored?
- How to replace jsx substring of a props - react
- Pass A Function Down But Retain A Prop From Parent
- How to change text, icon and underline color of Select in Material UI
- Express server routing issue - does not allow for other routes only home route working
- How to have Nginx to proxy pass only on "/" location and serve index.html on the rest
- Non lambda in React-Router V4 render function
- Data from state to FieldArray
- How to set the DefaultRoute to another Route in React Router
- create-react-library not working with styled components
- Navigate back to previous page within a container/div
- Change react props within component as optimization
- Test two different npm package versions at the same time
- React map() multidimensional array
- Get value from html input in antd form
- Redux + Typescript + typesafe-actions:
- Open a modal from a component
- React Hook Form reset Controller (value) to default
- How to redirect to home page(in jsx) after logout in react
- Trigger an alert after a particular time has passed from the current time when the button was clicked