- Counter App is simple counting app to either increment/decrement by 1 or update by certain number.
- App is built using ReactJs [built tool used: Vite]
Now, head over to your Terminal[being in project directory]
npm create vite@latest
cd <newly-created-project-directory>
npm i
npm run dev
- props have read only property
- props are used only to pass the data from parent to child component
- If we have to change the data, user interactivity, handleEvent then we have to use "state" of reactJs
- "state" are the react object used to handle user interactivity
Q. Named and Default export ?
Ans: export function without using "export default ".
So, in that case a same exact name(i.e import {funcName} from "./App"; ) of function should be used in
order to import it.
However, in default export function could be exported via any name
in index.js file.
Q. Difference b/w regular Js function & React component ?
Ans: Regular js function may or may not begin with capital
leters but react component name should begin with uppercase
Q. Difference b/w props & states ?
Ans: props is the "read only data" passed as argument from parent to child component in reactJs; so data is not modified here using props.
Whereas, states is the data which be updated and passed from parent to child component
let [count, setCount] = useSate(0);
Here, count
is the variable whose initial value is set to 0 and setCount
is used to update this variable.
<h1 className={count > 0 ? "green" : count < 0 ? "red" : null}>
{count}
</h1>
Here, I tried to change the className(class is predefined in Js) using Js.