Shyam Hande has Published 72 Articles

Composition vs inheritance in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 09:03:12

2K+ Views

Composition and inheritance are the approaches to use multiple components together in React.js . This helps in code reuse. React recommend using composition instead of inheritance as much as possible and inheritance should be used in very specific cases only.Example to understand it −Let’s say we have a component to ... Read More

Lifting state up in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:56:40

514 Views

Often there will be a need to share state between different components. The common approach to share state between two components is to move the state to common parent of the two components. This approach is called as lifting state up in React.jsWith the shared state, changes in state reflect ... Read More

Uncontrolled Component in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:52:15

324 Views

In controlled component form data is handled by React component by writing event handler for state updates. But in uncontrolled component, form data is handled by DOM itself.ref is used to receive the form value from DOM.Exampleclass UserNameForm extends React.Component {    constructor(props) {       super(props);     ... Read More

Working with forms in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:45:33

259 Views

In simple html form, the form elements keeps value with it internally and submit on form submission button.Example Form Example           User Name:               In above example, we have a simple input ... Read More

Working with lists and keys in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:40:42

411 Views

Displaying a list on UI in ReactMap is JavaScript function which will return a new array for provided array as shown below −const originalNumbers = [ 2, 4, 6, 8, 10]; const squaredNumbers = originalNumbers.map( (number)=> number * number); console.log(“Squared Numbers==”squaredNumbers);Building a list in React is similar with the use ... Read More

Conditional rendering in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:38:01

265 Views

Using conditional statements specific components can be rendered and removed . Conditional handling works similarly in JavaScript and React.jsExamplefunction DisplayUserMessage( props ){    const user = props.user.type;    if(type==’Player’){       return Player ;    }    If( type==’Admin’){       Return Admin ;    } }If statement ... Read More

Handling events in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:27:24

426 Views

There are some syntactical differences in writing events but it is handled similar to DOM elements event handling.The name of event handlers are written in camel case notations.ExampleEvent in simple html −    Add User Event in React with jsx:    Add User One of the difference is ... Read More

Understanding state in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:18:45

284 Views

State and lifecycle of component is very powerful to make things work in a dynamic applications.StateState is generally used in Stateful component. With the introduction of hook, we can add state in functional component as well now . The name of the hook is useState.State is a JavaScript object which ... Read More

Understanding components and props in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:15:47

167 Views

React applications are made up of components. Component are generally uses react elements. Components can be independent, reusable pieces.There are two types of components −Stateless component ( Basically JavaScript functions )Stateful component ( Uses JavaScript class feature )Both the components types receives a proprieties object generally called as props.Stateless component ... Read More

Rendering elements in React.js

Shyam Hande

Shyam Hande

Updated on 28-Aug-2019 08:08:15

565 Views

The smallest building blocks of React applications are the elements. Example of an element is −const message = Welcome, Steve;React DOM updates the actual DOM with the converted react elements. React components are made up of elements.Rendering element on DOMWe will have a parent div element in the main html ... Read More

Advertisements