Simple react snippets
rfc - React function component
import styles from './MyComponent.module.scss';
import { useState } from 'react';
export default function MyComponent() {
const [data, setData] = useState();
return (
<div className={styles.container}>
<div className={styles.content}>MyComponent$1</div>
</div>
);
};
rcc - React Class Component
import styles from './MyComponent.module.scss';
import React from 'react';
export default class MyComponent extends React.Component {
constructor(props) {
super(props);
};
render() {
return (
<div className={styles.container}>
<div className={styles.content}>MyComponent$1</div>
</div>
);
};
};
ue - useEffect
useEffect(() => {
$1
}, []);
rs - redux useSelector
const $1 = useSelector($2);
rd - redux useDispatch
const dispatch = useDispatch();
rrn - react router dom useNavigate
const navigate = useNavigate();
clg - console log
console.log($1)
ef - export from
export { $1 } from '.$2';
exp - export
export { $1 };
ed - export default
export default $1;
fd - function declaration
function MyComponent() {
$1
};
fe - function expression
const MyComponent = function() {
$1
};
af - arrow function
($1) => { $2 }
cla - class
class MyComponent {
constructor(data) {
Object.assign(this, data);
}
$1
};