সম্পাদনা
import {createRoot} from "react-dom/client"; import React, {useReducer} from "react"; function reducer(count, action) { if (action.type === "increment") { return count + 1; } if (action.type === "decrement") { return count - 1; } return count; } function App() { const [count, dispatch] = useReducer(reducer, 0); return ( <div> <button onClick={() => dispatch({type: "decrement"})}>-</button> <span>{count}</span> <button onClick={() => dispatch({type: "increment"})}>+</button> </div> ); } createRoot( document.getElementById("root") ).render(<App/>);
পূর্বরূপ