Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Manages counter state using useReducer hook for more complex logic.
import React, { useReducer } from 'react';
const reducer = (state, action) => {
switch(action.type) {
case 'INCREMENT': return { count: state.count + 1 };
case 'DECREMENT': return { count: state.count - 1 };
case 'RESET': return { count: 0 };
default: return state;
}
};
const ReducerCounter = () => {
const [state, dispatch] = useReducer(reducer, { count: 0 });
return (
<div>
<h2>Count: {state.count}</h2>
<button onClick={() => dispatch({type: 'INCREMENT'})}>+</button>
<button onClick={() => dispatch({type: 'DECREMENT'})}>-</button>
<button onClick={() => dispatch({type: 'RESET'})}>Reset</button>
</div>
);
};
export default ReducerCounter;React is a declarative, component-based JavaScript library for building user interfaces, primarily for single-page applications. It allows developers to create reusable UI components and manage application state efficiently.
Origin & Creator
Developed by Jordan Walke at Facebook in 2013.
Industrial Note
React is specialized for building dynamic, responsive web and mobile UIs, particularly in SPA and complex front-end applications.