You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//MyComponent.jsimportReactfrom"react";importHellofrom"./Hello";constMyComponent=()=>{return(<divclassName="container"><Hellotitle="hello opkoko"content="React is awesome!"/></div>);};exportdefaultMyComponent;
Component state
importReact,{useState}from"react";constComponentWithState=()=>{const[active,setActive]=useState(true);handleClick=(e)=>{setActive(!active);};constbuttonText=active ? "On" : "Off";return(<divclassName="ComponentWithState"><p>Click the button!</p><buttononClick={handleClick}>Click me!</button><p>{buttonText}</p></div>);};exportdefaultComponentWithState;
useEffect
importReact,{useEffect,useState}from"react";constUseEffectComponent=()=>{const[count,setCount]=useState(0);useEffect(()=>{// Update the document title using the browser APIdocument.title=`You clicked ${count} times`;},[count]);return(<div><p>You clicked {count} times</p><buttononClick={()=>setCount(count+1)}>
Click me
</button></div>);};exportdefaultComponentWithState;
importReactfrom"react";constComponentWithList=({ items })=>{return(<><h1>Awesome people list</h1><ul>{items.map((item)=>{return<likey={item.id}>{item.name}</li>;})}</ul></>);};exportdefaultComponentWithList;