title | description | created |
---|---|---|
React CheatSheet |
The most important and useful methods of React are given here. |
2022-10-30 |
Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in React.
npx create-react-app my-app
cd my-app
npm start
function App() {
return <div>Hello Developers</div>;
}
export default App;
function App() {
return <User name="Developer" />
}
function User(props) {
return <h1>Hello, {props.name}</h1>; // Hello, Developer!
}
function App() {
return (
<User>
<h1>Hello, Developer!</h1>
</User>
);
}
function User({ children }) {
return children;
}
function App() {
const isAuthUser = useAuth();
if (isAuthUser) {
// if our user is authenticated, let them use the app
return <AuthApp />;
}
// if user is not authenticated, show a different screen
return <UnAuthApp />;
}
React context allows us to pass data to our component tree without using props.
function App() {
return (
<Body name="Developer" />
);
}
function Body({ name }) {
return (
<Greeting name={name} />
);
}
function Greeting({ name }) {
return <h1>Welcome, {name}</h1>;
}
import { useEffect } from 'react';
function MyComponent() {
useEffect(() => {
// perform side effect here
}, []);
}