H
H
Harconnen2020-11-30 23:45:09
React
Harconnen, 2020-11-30 23:45:09

The component is not updated when passing "props"?

Good evening.
Please help, I can't figure out why.

There is a component whose state is passed to the child object

const [radioList, setRadioList] = useState([
    { id: 1, title: "input1" },
  ]);

......
// добавляю новый объект в состояние
const handleSetRadioList = (id, name) => {
    let stateRadioList = radioList;
    let obj = {};
    obj["id"] = id;
    obj["title"] = name;
    stateRadioList.push(obj);
    setRadioList(stateRadioList);
  };

.......
<SelectManualRadio
    handleSetRadioList={handleSetRadioList}
    radioList={radioList}
/>


In the child component, I display the state with the help of The picture is as follows: When adding an object, I check the state in the parent component "radioList" - everything has been added there . But in the child component, only objects that were in the "default" and there are no new ones - that is, the child component is not redrawn. This is the first time I've encountered this.

props.radioList.map((radio, key) =>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question