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?

1

2

3

4

5

6

7

8

9

10

<code>const demo = ()=> {

  const hi = ()=>{

    console.log('say hi');

  }

   

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

};

export default demo;

 

那么现在我想用componentWillMount函数, 有什么方法可以替换它呢?</code>

天蓬老师天蓬老师2869 days ago695

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(){

    1

    <code>console.log('componentWillMount')</code>

    }

    render(){

    1

    2

    3

    4

    <code>return(

      <p>hi</p>

    )

      }</code>

    }

    reply
    0
  • Cancelreply