Important ReactJs Interview Questions
Important ReactJs Interview Questions
Important ReactJs Interview Questions
1] What is React?
React is a flexible and efficient open source front-end JavaScript library which was
developed by Jordan Walke, a software engineer from Facebook in 2011. It used for
building user interfaces especially for single page applications. It is used for
developing view layer of web and mobile apps. React was first deployed on
Facebook’s News Feed in 2011 and later used in Whatsapp and Instagram.
The latest version at the time of writing this is v7.6.3 as captured in the
output.
$ node –version
4] What is JSX?
JSX stands for Javascript XML. It is a React extension which allows us to
write Javascript codes similar to XML or HTML. The JSX file makes React
application robust which boosts its performance. Like XML or HTML, JSX tags
have a tag name, attributes, and children.
Example:
render() {
return(
<div>
</div>
Example:
Function Welcome({msg}) {
Example:
render() {
Example:
Example:
<div>
</div>
);
Example:
constructor(props) {
super(props)
this.state = {
render() {
return (
<div>
<h1>{this.state.message}</h1>
</div>
}
export default StateFun;
Props State
Props are external and are controlled State is internal and are controlled
by renders. by React Component.
//incorrect way
//correct way
• Mounting –
There are 4 built-in lifecycles that are called when a component is
mounted.
i. constructor() – Constructor method is used to set the initial state of the
component.
iii. render() – This method re-renders the HTML inside the DOM.
Example:
<li key={number.toString()}>
{number}
</li>
);
The term “render prop” refers to a technique for sharing code between
React components using a prop whose value is a function.
A component with a render prop takes a function that returns a React
element and calls it instead of implementing its own render logic.
Example:
render() {
return (
</div>
);
Example:
return (
<div className="App">
<h1>Hello </h1>
);
Example:
return (
<div className="App">
<h1>Hello </h1>
</div>
);
Example:
constructor(props) {
super(props)
The installation is complete, you can verify the version of NPM installed
using the command:
$ npm –version
The latest version at the time of writing this is v7.6.3 as captured in the
output.
$ node –version
The latest version at the time of writing this is v12.22.1 as captured in the
output.
$ create-react-app –version
$ cd app_name
$ npm start
27] What is a router in React JS?
React Router is a powerful routing library built on top of React that helps you add
new screens and flows to your application incredibly quickly, all while keeping the
URL in sync with what’s being displayed on the page.
In these folders, some folders or files are not useable. Such as, .gitignore,
package-lock.json and in a public folder, this file is not usable: favicon.ico,
logo192.png, manifest.json, logo512.png, robots.txt. Replace your files with
this file and use.
Example:
if (error) {
response.send(error);
} else {
response.send(doc);
});
});
Example:
constructor(props) {
super(props);
this.handleMouseMove = this.handleMouseMove.bind(this);
this.state = { x: 0};
handleMouseMove(event) {
this.setState({
x: event.clientX,
});
render() {
return (
</div>
);
Example:
handleClick = () => {
this.props.history.push("path/to/push");
render() {
return (
<div>
</div>
);
};
Example:
-App.js
—–ParentComponent.js
render(){
return(
<div>
//call childComponent
</div>
);
}}
——-Child Component.js
return(
);
Example:
>
(event) =>
function App() {
return (
<div className="container">
<table>
<thead>
<tr>
<th>Product Id </th>
</tr>
</thead>
</table>
</div>
);
Example –
Example:
constructor(props){
super(props);
host: 'localhost',
user: 'root',
database: 'react_prac'
});
connection.connect();
console.log(connection);
render() {
return (
);
}}
Example:
render(
return(
)}
return (
<div style={{
backgroundImage: `url("https://via.placeholder.com/500")`
}}>
Hello World
</div>
);
function App() {
return (
<div style={{ backgroundImage: `url(${background})` }}>
Hello World
</div>
);}
element,
document.getElementById(‘root’)
);
Example:
> (event) =>
return (
<li>
<input key={props.id}
>
type="checkbox"
{props.value}
</li>
)}
export default CheckBox;
Example –