Horje
React hooks update parent state from child Code Example
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>
        )
    }
}




Javascript

Related
javascript learning Code Example javascript learning Code Example
how to query array of object in mongoos Code Example how to query array of object in mongoos Code Example
() = javascript Code Example () = javascript Code Example
how to use location.pathname Code Example how to use location.pathname Code Example
get time js Code Example get time js Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7