Home > other >  how can i refactor this code snippet from a class to functional component react?
how can i refactor this code snippet from a class to functional component react?

Time:09-28

i have this code inside a class, how could i keep the idea of ​​it but updating to use in a function component? I'm trying to change but I can't keep the current proposal

validate = value => {
    const {
      formApi: { getValue },
      name,
    } = this.props;

CodePudding user response:

const Component = ({formApi: {getValue}, name})=> {
    const validate = useCallback((value)=> {
    }, [getValue, name]);
}

CodePudding user response:

const component = (props) => {

    const validate = value => {
        const {
            formApi: { getValue },
            name,
        } = props
    }

}
  • Related