I want change area (element) when i call changeArea method on another component.
I want to like do this.
First, App.js
export default function App(props) {
const [area, setArea] = React.useState(<><Button/><Button/></>)
const changeArea = (element) => {
setArea(element);
}
return (
<div>
{<area/>}
<ChildApp changeArea={changeArea}/>
</div>
);
}
And, ChildApp.js
export default function ChildApp(props) {
// I want do call to change the area.
props.changeArea(<></Select></>);
…
}
Anyway this code is not working.
Error
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
PS. It’s a simplification of the way I want to do it.