How to specify a constructor with a functional component (fat arrow syntax)?

后端 未结 5 767
南笙
南笙 2020-12-15 16:46

Given this component:

import React from \'react\'
import ReactDOM from \'react-dom\'
import PropTypes from \'prop-types\'

const NewGoalInput = props => {         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-15 17:36

    you could set a useState as the first line inside of your functional component and add a function as "initial value":

    const MyComponentName = props => {
      useState(() => {
        console.log('this will run the first time the component renders!');
      });
      return 
    my component!
    ; };

提交回复
热议问题