Styled React Concepts and Syntax
Styled React Concepts and Syntax
1. React Components
- Class Components:
render() {
- Functional Components:
};
3. Props
4. State
increment = () => {
};
render() {
return (
<div>
<h1>{this.state.count}</h1>
<button onClick={this.increment}>Increment</button>
</div>
);
return (
<div>
<h1>{count}</h1>
</div>
);
};
5. Lifecycle Methods
- Class Components:
componentDidMount() {
console.log('Component Mounted');
componentDidUpdate() {
console.log('Component Updated');
componentWillUnmount() {
render() {
return <h1>Hello!</h1>;
useEffect(() => {
console.log('Component Mounted');
return () => {
};
}, []);
return <h1>Hello!</h1>;
};
6. Handling Events
alert('Button Clicked!');
};
};
<ul>
<li key={index}>{item}</li>
))}
</ul>
);
<List items={['Apple', 'Banana', 'Cherry']} />;
8. Conditional Rendering
};
e.preventDefault();
alert(value);
};
return (
<form onSubmit={handleSubmit}>
<button type="submit">Submit</button>
</form>
);
};
};
<ThemeContext.Provider value="dark">
<Child />
</ThemeContext.Provider>
);
<Router>
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
</nav>
<Routes>
</Router>
);
- Setting Up a Store:
switch (action.type) {
case 'INCREMENT':
default:
return state;
};
console.log(store.getState()); // { count: 1 }
- Common Hooks:
1. useState
2. useEffect
3. useContext
4. useReducer
5. useRef