L
L
lookingfor22020-10-22 16:58:22
React
lookingfor2, 2020-10-22 16:58:22

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}/>


child component

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});
        });
    }


The prop changes, but the data is not rewritten to the state, how to make the state change and, as a result, everything is re-rendered

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lookingfor2, 2020-10-22
@lookingfor2

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 question

Ask a Question

731 491 924 answers to any question