- what is reconciliation in react
- what is react fibre
- Named Import and default import
import {Title} from ‘./Title’ // it is not object destructuring - what is one way databinding in react
- whenever you have to change any veriable inside react, you have to use react kind of variable using useState
const Body = () => {
let searchText = "KFC";
return(
<>
<div>
<input
type = 'text'
placeholder = 'search'
value = {searchText}
onChange = {
(e) => {
searchText = e.target.value; // after writing value it will re-render itself so it will show same
// hardcoded value
}
}
/>
</div>
</>
)
}
every component in react maintain state in it
- what/why is state: react don’t track normal variable for re-rerendering if we will change the js variable it will not re-render the component so it will not be in sync with UI. to make sync with UI after changing in variable we should use useState() to create react variable. whenever react variable update it rerender the changed part of component using reconciliation
- what/why is hooks : just a normal js function,
- what/why is useState : to create state variable, it returns an array, first name of this array is variable
const Body = () => {
// used to create localState Variable
let [searchText, setSearchText] = useState("KFC"};
return(
<>
<div>
<input
type = 'text'
placeholder = 'search'
value = {searchText}
onChange = {
(e) => {
searchText = e.target.value; // after writing value it will re-render itself so it will show same
// hardcoded value
}
}
/>
</div>
</>
)
}
Chapter 06: Exploring the world
- why react is fast
because of faster DOM manupulation (virutual DOM and fast diff algo) - changing input will re-execute that component but it will update the value of changed part only
- useEffect takes 2 params (callback function and dependency array), if dependency array is empty it will called once if it don’t have dependency array it will call on afterevery re-render
- there are 2 ways why component re-render 1. on state changes 2. on props changes
const Body = () => {
// used to create localState Variable
let [searchText, setSearchText] = useState("KFC"};
useEffect(() => {console.log('useEffect called')}, []);
console.log('render()');
return(
<>
<div>
<input
type = 'text'
placeholder = 'search'
value = {searchText}
onChange = {
(e) => {
searchText = e.target.value; // after writing value it will re-render itself so it will show same
// hardcoded value
}
}
/>
</div>
</>
)
}
output:
render()
useEffectCalled
==============
//useEffect call back function called after render/re-render
- empty dependency array => once after render
- dep array [searchText] => once after initial render + everytime after re-render after (my searchText changes)
Q) how browser works? painting and all .. critical browsing path and alll ..
inside JSX using {} you can write js expression not statement