React Q & A
React Q & A
1. What is Reactjs?
A. React js is a javascript library, it was developed and maintained by
facebook. Mainly using the reactjs we can develop the faster web
applications compare to other technologies.
2. What is Dom?
A. Dom Means document object model(DOM)
It is a child object to the window, it is used to add dynamic content to the
html pages, and also to add dynamic validations.
When html document is loaded in the browser it becomes a document
object.
A. Props drilling means it will pass data from parent component to child
components.
B. For example I have 20 components, need to pass data 1st component to last
component (20th component), that time we can pass data one component to two
component two to three component and three to four component any way we
can pass 20th component. But if any component is not working means getting
error it will not pass data nth components this is the draw back props drilling.
A. Context api means it will pass date from one component to any other
component with out any relation ship using the context.provider and
context.consumer.
1. Initial phase
2. Mounting phase
3. Updated phase
4. Unmounting phase
1. Constructor
2. getDerivedStateFromProps
3. Render
4. componentDidMount
Updating Phase:
1. getDerivedStateFromProps
2. shouldComponentUpdate
3. Render
4. getSnapshotFromBeforeUpdate
5. componentDidUpdate
Unmounting phase
1. componentWillUnMount.
2. componentDidUpdate
3. componentWillUnmount
ComponentDidMount:
Whenever using the useEffect methos it will pass the 2 arguments 1st argument
as a callback function 2nd argument as a empty dependencey array. That time it
will call as a componentDidMount.
Function App(){
useEffect(()=>{
Fetch(‘url’);
}, [] )
Return(
<div
</div>
Function App(){
useEffect(()=>{
Fetch(‘url’);
}, [data] )
Return(
<div
</div>
Function App(){
useEffect(()=>{
Fetch(‘url’);
Return function(){
//code
}, [] )
Return(
<div
</div>
B. only call hooks at the top level of your react function i.e..,don’t call hooks
inside loops,conditions or nested functions and class component
1. useState
2. useEffect
3. useMemo
4. useCallback
5. useRef
6. useReducer
7. useContext
8. useSelector
9. useDispatch
10.useStore
B. Setter method
const [city,setCity]=useState(“atp”);
2. useEffect:-useEffect is a hook method it is equalent to the 3methods
1.componentDidMount
2.componentDidUpdate
3.componentWillUnmount
ComponentDidMount:
Whenever using the useEffect methos it will pass the 2 arguments 1st argument
as a callback function 2nd argument as a empty dependencey array. That time it
will call as a componentDidMount.
Function App(){
useEffect(()=>{
Fetch(‘url’);
}, [] )
Return(
<div
</div>
Function App(){
useEffect(()=>{
Fetch(‘url’);
}, [data] )
Return(
<div
</div>
Function App(){
useEffect(()=>{
Fetch(‘url’);
Return function(){
//code
}, [] )
Return(
<div
</div>
Ex:- I have one component there is a one calculation part is there once
application Re-render it will get directly value no need to calculate again and
again.
4.useCallback():- useCallback is a hook method whenever using the
useCallback it will return as a memorized function
Ex:- I have one parent component inside some child components once parent
component state is updated it will Re-render the inside child components also
need to avoiding that we are using the useCallback
Ex:- const[state,dispatch]=useReducer(state,action){
Switcth(action.type){
//code //
6.useRef():- useRef is a hook method it is mainly using the focus on the input
field
2.React follows one way data binding 2.Angular follows two way data binding
3.React follows View part only in MVC archietecture 3.Angular follows MVC archietecture
4.React application is faste as compared to Angular 4.Angular application is slow compared to React
A:- super is a method it will acquire the data from parent component to child
component
A:- return is a controlled statement used to return that statement to the calling
place. Return keyword is helped to display the browser
A:- event is a one of the action that will provide interaction between html tags
to javascript
Uncontrolled Component:
Example: we are creating div it will create the extra node instedof div we are
writing the React.fragment
Ex: we have one parent component inside some child components have
Once the parent component is updated it will Rerender the child components
also, so we need to stop the re rendering inside child components.
Ex: we have one parent component inside some child components have
Once the parent component is updated it will Re-render the child components
also, so we need to stop the re rendering inside child components.
A. React Router we can’t able to use directly in React. It is a Third party library we need to
install librarie i.e.,
command:-npm i react-router-dom
Mainly we are using the React router dom is Navigation Purpose like one page to another
page navigation.
Whenever creating the React router dom we need to use Browser router,Routes,Route
Axios Fetch
1.Need to install 3rd party libraries npm i axios 1.No need to install any 3rd party libraries
2.No need to convert the data in JSON format 2.Need to convert the data in JSON format
3.we can able to easily handle the Errors in Axios 3.it is very difficult to handle the Errors in Fetch
componentDidMount() {
console.log('Component mounted');
}
componentWillUnmount() {
console.log('Component unmounted');
render() {
return WithLogger;
};
// Usage
render() {
1.Action :-
=> Store:-
For entire redux application we have to create single store that will work as a
global store
=> store contains provider to make state is available to all the components in
application.
View Components:-
=> view components are the Components here we will get or access from
redux store to update UI.
Middlewares:
Pure Function: