-
Plugins
- ESLint
- prettier
- material
-
Dev packages
- Node.js latest LTS version
- tsx = typescript on react
-
Format
- CamelCase Componant Naming
-
Craco
- helps with routes/paths replacing all "../../App" with just "@/App"
-
Components
- declare components as functions and export them
- Header.tsx file
function Header() { //view return <h1>Header</h1>; } export default Header;
-
Props
-
declare props with type (typescript) keyword
-
use ? to make props elements non-required
-
Props usage with Components:
-
Header.tsx file:
type Props = { name: string; title: string; description: string; }; function Header({ name, title, description }: Props) { //view return ( <> <h1>{name}</h1> <h2>{title}</h2> <h2>{description}</h2> </> ); }
-
App.tsx file:
/** * Root Component * @see https://www.jumanazar.uz/react-practice */ function App() { //js //view return ( <> <Header name="Jumanazar" title="Java Engineer" description="SweetK" /> </> ); }
-
-
-
Styled-Components
- use -D to install it as dev dependency which is not added in deployment build
-
useState
- const [count, setCount] = useState(0);
-
events
- uses const func = (evt: ChangeEvent) = >{};
//event const onChange = (e: ChangeEvent<HTMLInputElement>) => { const value = e.target.value; setInput(value); };
-
useEffect
- usage:
//watch useEffect(() => { //init console.log(inputValue); }, [inputValue]);
- is used for watching some change.
- ex: call some API when some value changes such as useState value.
- usage:
-
ToList App
-
use
map
for rendering lists -
using
forEach
does not work because it does not return anything.
-
- to use children routes, use `Outlet` from `react-router-dom`
- Link
- NavLink - has more features
- Redux alternative, but official and more reactish library
- Redux is 3rd party, and has great learning curve
- dependencies:
- yarn add axios
- yarn add env-cmd
- project
-
TypeScript -D
- TypeScript devDependencies are necessary only for developmen purpose. All typescript codes are transpiled into JavaScript while production build
-
atom is used for generating default values for our loginState
const loginState = atom<LoginInfo>({ key: "loginState", default: { userId: "", userPwd: "", isLogin: false, }, });