showing results for - "react setstate in another component"
Anton
18 Sep 2020
1// myContainer.js
2import React, { useState } from 'react'
3import MyChild from 'some/path/myChild'
4
5function MyContainer() {
6  const [name, setName] = useState('foo')
7
8  return (
9    <MyChild name={name} onNameChange={setName} />
10  )
11}
12
13export default MyContainer
14
15// myChild.js
16import React, { useCallback } from 'react'
17
18function MyChild({ name, onNameChange }) {
19
20  const handleInputChange = useCallback(event => {
21    onNameChange(event.target.value)
22  }, [onNameChange])
23
24  return (
25    <div>
26      <input type="text" onChange={handleInputChange} value={name} />
27      <div>The name is: {name}</div>
28    </div>
29  )
30}
31
32export default MyChild
33
queries leading to this page
how to call this setstate from another componentsetstate in another componentaccess state of one component on another componentsetstate from another componentsetstate pass in another componentsetstate react one after anothersetstate in another component hookspass setstate to another componentcan i use one component of state in another component in react jsset component state from another componentcall setstate of another component via propssetstate other state reacthow to pass setstate onto another component react nativereact setstate of another componentreact setstate in other componentusing state in another componentreact setstate from another classhow to change setstate of one component from another component in reactreactjs setstate of component from another componentsetstate inside another setstate reactcall setstate of another component in renderreact transfer setstate to other componenthow to call setstate from other component reactjscan i pass setstate to another componentcan i call setstate in another function in reactsetstate of element from anothersetstate to another varthis setstate from another funciton reacthow to setstate from another componenthow to setstate of one component in another component reactstate in one component to anotherhow to set the state in another class component setstateset state from another componentsetstate with other statesreact setstate from another componenthow to setstate on a class from another componentcalling setstate from another component how to setstate from another component reactsetstate of anotherreact set state from another componentcall setstate from another componentcalling setstate from another component functional reactreact setstate in another componentdefine usestate in one component and setstate in another componentsetstate to another stateuse a state in another componenthow to setstate of another component reactcan we use setstate in another functionset state of another component reactreact setstate based on another statehow to use what is insie this setstate in another componenthow to setstate in another component reactset state that comes from another component reacthow to setstate in react hooks in another componentreact native setstate of another componentsetstate from another functionsetstate from another component in react jsusing a state from one component to anothercall setstate in another component state in another componentreact setstate another componentreact setstate in another component