Home > other >  Js to Reactjs conversion
Js to Reactjs conversion

Time:07-25

Hello I am looking for convert this Js to ReactJS with the best practice.

$crisp.push(['do', 'chat:open']);
<button onclick="$crisp.push(['do', 'chat:open'])">Click Me!</button>

Thanks for your Help

CodePudding user response:

you can try creating a state called crisp with react hooks (using functional component):

import React,{useState} from 'react';
function MyComponent(){
        let [crisp,setCrisp] = useState([])
        function handleOnClick():
                 setCrisp(
                      [
                      ...crisp,
                       'do','chat:open'
                      ]
                    )
       return(
         <button onClick = {()=>handleOnClick()}>Click me!</button>
)
}
  • Related