score:0
renderbutton
is a function component and, therefore, needs to be in pascalcase:renderbutton
(although it would be better off asbutton
).move
handleclick
to thechild
component.then in
button
the call tohandleclick
should beprops.handleclick
sincehandleclick
will now be a property of theprops
object passed into the component. we don't need to pass down the data as a prop to the button but can, instead just log the data prop passed intochild
.handleclick = () => { console.log(`handleclick(): ${props.datafromapp}`); }
in
child
, instead of callingrenderbutton
, importbutton
, and then use that in the render passing down the handler in the props. by doing this you're making the component as "dumb" as possible so it can be reused elsewhere in the application.<button handleclick={this.handleclick} />
Source: stackoverflow.com
Related Query
- ReactJS - How to implement a callback function from JSX
- How To Call A JavaScript Function Returned From NodeJS in ReactJS JSX
- moving from twig to ReactJS: how to extend a template/component to build full reactJS pages? implement react-router and redux into symfony?
- How to return an empty jsx element from the render function in react?
- How to return a React memoized callback from factory function
- How to call another component from onClick function in ReactJS
- How to correctly implement a props callback function in the useEffect hook
- How do you call a jQuery function on a ReactJS element from .jsx script?
- How to access state from callback function
- How to implement a callback function in React Native?
- How to implement remember me functionality for authentication in ReactJS when i only receive jwt token from backend api
- How to handle multiple onChange function from multiple input fields in Reactjs
- How to pass callback function to litelement from React?
- How to access reactjs component state in jquery callback function
- How to pass a ReactJS function as a callback to a external JS function?
- Need Reactjs help on how to properly pass this function from the parent to child button component
- How to callback a function on onClick event in ReactJs
- How to redirect to a route from an external function in ReactJS
- Use "this" pointer from inside map callback function using ReactJs
- How to update a function with useEffect (like componentDidUpdate) and use .map function to display from JSON file ReactJS
- How can I make a function Async in reactjs which calls another two functions from redux actions
- How to setState in child component when child function called from parent component in ReactJS
- How to call a class function from another in ReactJs
- How to call Parent containers function from child component in Reactjs
- How to store value from callback function in react state? (Google Maps)
- How to call function in ReactJS in a callback within the same component?
- how to pass props to a function from a button in reactjs
- ReactJS Change the JSX from onClick function
- How to implement a generic arrow function as interface property in Typescript with React JSX
- How to remove one item from an array using filter() in ReactJS - function not working properly
More Query from same tag
- React onScroll not firing
- React Testing Library / React Router
- React JS - Problem with local storage, .map() and textarea value
- Formik re-renders on react state change
- Set Private Route to Parent Layout to prevent 'uid' getting undefined
- ReactJS two way binding not working, somewhere wrong with binding
- How to change react-bootstrap navbar-toggler-icon button and button color
- How to fix "Failed prop type: The property `spacing` of `grid` must be used on `container`?
- React - Children Accessing Parents state too early?
- React - unable to get the store state to pass in a child class component
- Global is not defined when trying to use `interweave` in an `Electron-React-Typescript-Webpack` app
- Best way to convert URL query params into a formatted array
- How to refactor a react sign in component into an existing material ui sign in component?
- Cannot access public method in type Typescript class
- How do I dynamically toggle multiple layers in Deck.gl?
- Reflux avoid hitting server every time, when data cached locally
- Why doesn't the message POST
- Error: Response not successful: Received status code 400
- Default dynamic route in Next.js
- Material UI React Slider Component Not Working on mobile
- Unable to type in input field React
- Socket connection not getting established when using https
- Ajax call to Express app does not pass data
- How to create a backend to hide API keys in Reactjs app?
- setInterval in a promise, only executes once in React
- Unable to import local photo in react native. Getting Error "None of these files exist:"
- How to define a state with JSON data (using react and axios)
- How can I Fetch and display Mysql data into ReactJS front end with Node JS as backend?
- React: Event-triggered Ajax call in componentDidUpdate or render creates infinite loop
- how to hide div on click in react