React hooks update parent state from child
const EnhancedTable = ({ parentCallback }) => {
const [count, setCount] = useState(0);
return (
<button onClick={() => {
const newValue = count + 1;
setCount(newValue);
parentCallback(newValue);
}}>
Click me {count}
</button>
)
};
class PageComponent extends React.Component {
callback = (count) => {
// do something with value in parent component, like save to state
}
render() {
return (
<div className="App">
<EnhancedTable parentCallback={this.callback} />
<h2>count 0</h2>
(count should be updated from child)
</div>
)
}
}
Also in JavaScript:
- change style on click react
- convert json to arraylist java
- javascript scrollleft stop
- java serialize object to json
- localecompare javascript
- ckeditor get content html
- unban command discord.js v12
- axios response return html not json data
- how to use react router
- can you get reinfected with the coronavirus
- expo app.json
- appendchild element once if element present in js
- generate random number javascript
- mocha js
- trigger click jquery
- manifest.webmanifest example
- js reload page 1024 breakpoint
- require("history").createBrowserHistory` instead of `require("history/createBrowserHistory")`
- change favicon with javascript
- get unchecked checkbox jquery
- javascript remove object from array
- axios post with header
- docker node placement constraints
- javascript json to array