Answer the question
In order to leave comments, you need to log in
Why doesn't a new render happen when props change?
parent component
Тут переменные с данными
const dataSystem = {
data: GetSystem,
title: 'Системные сообщения',
};
const dataServices = {
data: GetServices,
title: 'Кредитный рейтинг',
};
хук с состоянием
const [objectOperationsData, setObjectOperationsData] = useState(dataLoan);
дочерний компонент, куда передаем objectOperationsData
<RenderData props={objectOperationsData}/>
class RenderData extends Component {
constructor(props) {
super(props);
this.state = {
obtainedData: {},
loading: false,
};
}
componentDidMount() {
console.log(this.props.props.data().then(response => {console.log(response.data)}))
this.props.props.data().then(response => {
this.setState({obtainedData: response.data});
this.setState({loading: !this.state.loading});
});
}
Answer the question
In order to leave comments, you need to log in
Separately, it is worth noting the componentWillReceiveProps(nextProps) function, which is called when the props object is updated. The new values of this object are passed to the functions as a parameter. As a rule, those properties of the component, including those from this.state, that depend on the values from props are set in this function.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question