I am wondering if there is a way to update a state in a parent functional component from a child component using a function, something similar to the below example for class components:
<ParentComponent name={ this.state.name } email={ this.state.email } setValues={ ( state, value ) => { this.setState({ [state] : value }) }} /> <ChildComponent> <input type={ 'text' } value={ this.props.name } onChange={ ( event ) => { this.props.setValues( 'name', event.target.value ) }} /> <input type={ 'email' } value={ this.props.email } onChange={ ( event ) => { this.props.setValues( 'email', event.target.value ) }} /> </ChildComponent> I need something similar in a functional component using Hooks if possible.
Let me know if more information is required.
Thanks in advance.
this.setStatebut that simply becomes the relevant state updater function) - in fact not a single class is even shown in your code!