M
M
Mk552020-03-04 15:02:11
React
Mk55, 2020-03-04 15:02:11

When the state in the child component has changed, how do I send these values ​​to the parent component?

and how to do it with hooks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Cheremkhin, 2020-03-04
@Che603000

States in React are passed from top to bottom. (from parent to child). Typically, a parent component receives an action from a child component using functions.

const Parent= props =>{
  const [active, setActive] = useState(0);

  const onSeleсt = index =>{
    setActive(index); 
  };

  return <Items  active={active} onSelect={onSelect} {...props}/>;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question