Reactjs convert class components to functional components

前端 未结 3 1592
渐次进展
渐次进展 2020-12-22 05:47

I am new in react. I want to use form stepper in my project. I found one library but in that library using class components. I am little confuse convert class components to

3条回答
  •  庸人自扰
    2020-12-22 06:46

    Replace your constructor and functions with this code, basically you don't need a constructor and 'this'.

    const [page, setPage] = React.useState(0);
    const [steps, setSteps] = React.useState([ 
            {title: 'Visitor Details'},
            {title: 'Personal Details'},
            {title: 'Nominee Details'}
            ])
    
    function nextPage() {
        setPage(page + 1)
      }
    
    function previousPage() {
        setPage(page - 1)
    }

提交回复
热议问题