小编Rea*_*tor的帖子

React- createRef() Api - this.child.current is null

In order to allow my parent component (JsonFetcher) to access values from my child component (Display), I tried using createRef() API that just came of this patch 16.3

Following the "Adding a Ref to a class Component" example in this document, here's what I tried in my code:

class JsonFetcher extends Component {
    constructor(props) {
        super(props);
        this.child = React.createRef();
        this.state = {
            data: [],
        }
    }

    componentDidMount() {   
        this.updateContent(this.props.mainUrl)
    }

    updateContent(mainUrl){
        fetch(mainUrl)
            .then((responseJsonAnyUrl) => responseJsonAnyUrl.json()) …
Run Code Online (Sandbox Code Playgroud)

reference ref reactjs

6
推荐指数
1
解决办法
8050
查看次数

标签 统计

reactjs ×1

ref ×1

reference ×1