-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
// Model
const initialData = {
counter: 0
};
// ViewModel
const useCounterViewModel = () => {
const [data, setData] = useState(initialData);
const incrementCounter = () => {
setData(prevData => ({
...prevData,
counter: prevData.counter + 1
}));
};
return { data, incrementCounter };
};
// View
const CounterView = ({ counter, onIncrement }) => {
return (
<div>
<p>Counter: {counter}</p>
<button onClick={onIncrement}>Increment</button>
</div>
);
};
const App = () => {
const { data, incrementCounter } = useCounterViewModel();
return <CounterView counter={data.counter} onIncrement={incrementCounter} />;
};
ReactDOM.render(<App />, document.getElementById('root'));Metadata
Metadata
Assignees
Labels
No labels