How to initialize state? with data after fetching data

import React from "react";
class Demo extends React.Component{
  constructor(props){
    super(props)
    this.state{
      initData: ""
    }
  }

  render(){
      return(
        <div>{ this.state.initData }<div>
      )
  }
}
function mapStateToProps(state) {
  const { demoData } = state.demo;
  return { demoData };
}
export default connect(mapStateToProps)(Demo );

how do I initialize state with demoData? Several hook functions were used without success.

Mar.23,2021

initialize state. with demoData What do you mean?


componentWillReceiveProps (nextProps) {

if(nextProps.demoData  !== this.props.demoData){
    this.setData({
       initData: nextProps.demoData 
    })
}

}

Menu