It is a class that extends React.Component and it has a render method that returns JSX
constructor will call parent class's constructor using super()
State can be intialized in constructor
componentDidMount
componentDidUpdate
componentWillUnmount
It follows Single Responsibility principle so that your code becomes readable, maintainable, reusable and testable
Best practise it to start custom hook file names with "use" to let others/readers know that it is a custom hook
These are nothing a custom java script functions that returns a value which you can use it in your components
lazy() is used for loading component on demand when user clicks or navigates to that route
import() function is used to bundle files seperately/ create seperate chunks and will be loaded when user clicks/navigates
It is a JavaScript function that takes a component as input, enhances it and returns the enchanced component
1 - UI Layer -> JSX
2 - Data Layer -> Local variables, state, props, curly braces inside JSX that modifies the UI
If a component is being controlled by its parent or if a component is relying on its parent then it is called Controlled Component
If a component controlled by itself then it is called Controlled Component (having own state)
- Install @reduxjs/toolkit and react-redux
- Build our store
- Connect store to our app
- Slice (CartSlice)
- dispatch action (addItem)
- Selector (subsribing to the store to get data)
- Redux Dev Tools
- Install React Testing Library (RTL)
- Install Jest
- Install Babel dependencies (while using Jest with Babel)
- Config Parcel to disable default Babel transpilation- Update .parcelrc file to use the Babel that we installed above. Because react app will be confused which Babel to use? Babel that comes with parcel or the Babel that was installed above for testing.
- npx jest --init for jest config file
- Install jsdom library as Jest version is > 28, it has stopped including jsdom environment along with jsdom
- Install @babel/preset-react - for JSX to work in test cases
- Include @babel/preset-react in babel.config.ts file
- Include @testing-library/jest-dom to access 'toBeInTheDocument' (basically for assertion)
- Install @types/jest
- Install @babel/preset-typescript - This is just used to transpilation, wont check for types
- To check types, install ts-jest and update settings in jest config file : preset: 'ts-jest'
- It is used to cache the result of complex operation/calculation between re-renders
- It will recalcaulate only when the dependencies change
- It is used to cache the function definition between re-renders
- It is used to reference a value that is not needed for rendering
- const/let variables can store data but they wont retain it when the component re-renders
- If referenced value is updated, it will reflect once the component re-renders