P
P
parcnfalb2018-11-30 15:49:15
React
parcnfalb, 2018-11-30 15:49:15

Why can't I put props in the state and send this state to the child component?

A number comes to the props of this component on click (initially null),
If you pass < Work update={this.props.update}/ > as props below, then everything works
If you pass < Work update={this.state.update}/ > as state does not work.
The question is why does it work this way?
I'm reassigning a prop to a state, and I want to use the state to pass it to the component below, why is it just passing empty to me?
In the < Work/> component, it simply renders as < div>{this.props.update}< /div>

import React, { Component } from 'react'
import Work from '../Work'

export default class ArticleList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            update: this.props.update
        }
    }


    render() {
        var workList = (
            <Work
                update={this.props.update}
            />
        )

        return workList
    }

}

Yes, I understand that I do not understand something

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-11-30
@dimoff66

If you pass < Work update={this.state.update}/ > as state then it doesn't work.

It doesn't matter how you send. If at the time the line is called, the value of this.state.update is true, then in this form it will also fall into Work, but the above code is silent about what happens to your state. See with a debugger what this.state.update contains

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question