Book Name : Philosopher's Stone
Price : $1,953.77
Book Name : Chamber of Secrets
Price : $2,736.72
Book Name : Prisoner of Azkaban
Price : $3,555.92
Book Name : Goblet of Fire
Price : $2,626.20
Book Name : Order of the Phoenix
Price : $2,006.03
Book Name : Half-Blood Prince
Price : $2,387.31
Book Name : Deathly Hallows
Price : $1,224.24
Book Name : The Hobbit
Price : $2,040.29
Book Name : The Fellowship of the Ring
Price : $1,090.16
Book Name : The Two Towers
Price : $3,280.79
Book Name : The Return of the King
Price : $2,394.97
Book Name : The Silmarillion
Price : $1,239.18
Props:
Props is a short from of proparties.
Welcome name="Sara"
Here Welcome is a component that passing the value sara via name property.
Welcome.js will use that value with props.Props can only use the value that has been passed.props can not set it's value and also can not reset the value that has been passed.
State:
Like props, state holds information about the component. However, the kind of information and how it is handled is differently. When a component needs to keep track of information between renderings the component it can use state.
Example: useState , useEffect
Unlike props states value can be changed.
Example : const [count, setCount] = useState(0);
setCount(count+1)
if we use this setCount in a button every time button is clicked use state will reset the value of count.
So we can say that both props and state can hold information about the component. But they works differently
useState is a Hook from React. A hook is a special function that we can use from React features. To use useState we have t import it from react in header.
Example : import React, useState from 'react';
in the body useState is declared like const [count, setCount] = useState(0);
useState returns 2 values one is a variable and a function. here count is a variable and setCount is a function. If we call the function setCount and pass a value in the function. useState takes that value and pass that value to the count variable so that we can use that count variable as an object.