Skip to content Skip to sidebar Skip to footer

React State Data Null For The First Time

I am taking 'data' from the api.For the first time when component render it is getting data as null but after some time it is having api data.I am getting data from api but not abl

Solution 1:

I think you have two good options:

  1. Sepcify default props for the component https://facebook.github.io/react/docs/typechecking-with-proptypes.html#default-prop-values

  2. In render method declare a default value for the data: const {data = {}} = this.props;

3.

return(
      {this.props.data && <div>
        {console.log(data)};
      </div>}
    )

Post a Comment for "React State Data Null For The First Time"