Best Online Tutorials

SQL Tutorial

Free SQL Tutorial

SQL Interview Questions

SQL Practice Questions

SQL Tips & Tricks

SQL Errors

SQL Books

Angular Tutorial

Free Angular Tutorial

Angular Interview Questions

Angular Practice Questions

Angular Tips & Tricks

Angular Errors

Angular Books

Node.js Tutorial

Free Node.js Tutorial

Node.js Interview Questions

Node.js Practice Questions

Node.js Tips & Tricks

Node.js Errors

Node.js Books

React.js Tutorial

Free React.js Tutorial

React.js Interview Questions

React.js Practice Questions

React.js Tips & Tricks

React.js Errors

React.js Books

SSIS Tutorial

Free SSIS Tutorial

SSIS Interview Questions

SSIS Practice Questions

SSIS Tips & Tricks

SSIS Errors

SSIS Books

SEO Tutorial

Free SEO Tutorial

SEO Interview Questions

SEO Practice Questions

SEO Tips & Tricks

SEO Errors

SEO Books

Javascript Tutorial

Free Javascript Tutorial

Javascript Interview Questions

Javascript Practice Questions

Javascript Tips & Tricks

Javascript Errors

Javascript Books

MongoDB Tutorial

Free MongoDB Tutorial

MongoDB Interview Questions

MongoDB Practice Questions

MongoDB Tips & Tricks

MongoDB Errors

MongoDB Books

Next.js Tutorial

Free Next.js Tutorial

Next.js Interview Questions

Next.js Practice Questions

Next.js Tips & Tricks

Next.js Errors

Next.js Books

React.js Interview Questions - Part 4 

Prashant Surya  |   Mar 16, 2020  |  Views: 82


31. How to bind "this" scope with callback methods without calling the bind in constructor?

There are two ways to do so by using the:

1. Experimental public class fields syntax
2. Arrow functions

Experimental public class fields syntax:
- This syntax is enabled by default in Create React App.

class Demo extends React.Component {
  // This syntax ensures `this` is bound within handleClick.
  // Warning: this is *experimental* syntax.
  handleClick = () => {
    console.log('this is:', this);
  render() {
    return (
      <button onClick={this.handleClick}>
        Click me

Arrow functions:

class Demo extends React.Component {
  handleClick() {
    console.log('this is:', this);
  render() {
    // This syntax ensures `this` is bound within handleClick
    return (
      <button onClick={() => this.handleClick()}>
        Click me

Note: It is recommend that binding in the constructor or using the class fields syntax is good, to avoid this sort of performance problem.

32. What is Uncontrolled Component?

HTML form elements work a little bit differently from other DOM elements in React, because form elements naturally keep some internal state. 

In uncontrolled components, where form data is handled by the DOM itself.

33. How to set the default value to the input tag in uncontrolled component?

- we have to use defaultValue /defaultChecked attribute instead of value on element tag.

render() {
  return (
    <form onSubmit={this.handleSubmit}>
        Enter your Name:
          ref={this.input} />
      <input type="submit" value="Submit" />

34. What are the different tags and have different attributes to set default value?

input (checkbox) : defaultChecked
input (radio):     defaultChecked
select:            defaultValue
input (others) :   defaultValue
textarea :         defaultValue

34. What is controlled Component?

In Reactjs, mutable state is typically kept in the state property of components, and only updated with setState().

So here we have control over the state of the elements and can easily manage using setState().

35. What do you mean by “single source of truth”?

An input form element whose value is controlled by React in this way is called a “controlled component” which maintains the “single source of truth”.

36. What are the alternatives to Controlled Components?

We can use uncontrolled components.

Or we can use Formik  which is a complete solution including validation, keeping track of the visited fields, and handling form submission.

Formikis one of the popular choices. It is built on the same principles of controlled components and managing state.

37. What are Reactjs Keys?

Keys play an important role while using the list in reactjs.

Assigning a unique key increases the updation process by uniquely identify the record and update only the changed item.

Keys should be given to the elements inside the array to give the elements a stable identity.

It help React  to identify which item has been changed, added, or been removed.

Its better to give the key a unique Id, for best performance.

38. What are ReactJS Refs?

Refs are used to access DOM nodes or React elements created by render method.

It is used to return a reference to the element.

Don’t Overuse Refs.

39. When to Use Refs?

Managing focus, text selection, or media playback.
Triggering imperative animations.
Integrating with third-party DOM libraries.

40. How to create a ref?

React.createRef() is used to create refs.

ref attribute on react elements are added to attach with the refs created by React.createRef()

Refs are commonly assigned to an instance property when a component is constructed so they can be referenced throughout the component.

Content Contributor
Prashant Surya

Prashant Surya

Software developer at Uniserve Data Technologies Pvt. Ltd.  |   Noida, Uttar Pradesh, India

I am a software developer, freelancer and trainer working on technologies likes. MEAN stack, MERN Stack, ASP.NET full stack , SQL, JavaScript, jQuery, HTML, CSS, SEO, responsive UI/UX designing... having 7 years of experience in development in multiple domains like, eCommerce, capital markets, education, real estate...

Want to sell your software ?-

If you want to sell your readymade software to the genuine clients or businessman, list your software with details and demo links.

  • Sell ERP
  • Sell Website Clones
  • Sell App Clones
  • Sell Readymade Portals
  • Sell Readymade Websites
  • Sell Mobile Apps
  • Sell Window Apps

Clients will find it using our advanced search filter and will contact you directly.

No any charge for the product lsiting.

Do you own a Company ?+

Buy or Sell Commercial Property+

Are you a freelancer ?+

Looking for a job ?+

Are you a Service Provider ?+

Are you a blogger ?+

Do you own an IT Institute ?+