search

Home  >  Q&A  >  body text

javascript - What should I use to replace the componentWillMount life cycle function?

How can we replace the previous componentWillMount function with the current functional writing method?

const demo = ()=> { 
  const hi = ()=>{
    console.log('say hi');
  }
  
  return ( <p>hi</p> );
};
export default demo;

那么现在我想用componentWillMount函数, 有什么方法可以替换它呢?
天蓬老师天蓬老师2788 days ago661

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-19 10:20:58

    Pure Function Component (PFC) has no lifecycle. If you need these callbacks, don’t force this.

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:20:58

    export default class Test extends React.Component{

    componentWillMount(){

    console.log('componentWillMount')

    }

    render(){

    return(
      <p>hi</p>
    )
      }

    }

    reply
    0
  • Cancelreply