
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 224 Articles for Javascript Library

421 Views
The aria-* attributes on html elements are also supported in React.js as well. The other attributes are generally written in camel-case but these aria-* are written in hyphen-cased.Sometimes we break the semantics of the html if we use parent div in React.jsExamplerender(){ return( Test ); }Div can cause semantics issue if working with table, list etc. To avoid this we can use React provided fragment as shown below −import React, { Fragment } from ‘react’; function MessageList({ message }) { return ( ... Read More

642 Views
React community has provided a direction on how to think in React way and build big , fast and scalable applications. React has reached multiple platforms and widely used a popular JavaScript UI interface library.Step 1 − Creating a simple mock serviceIf we need to make a server call and fetch data. We can create a mock service to start with and build a component to fetch and display data.Here we can include the processing of json in component and evaluating the expected result.Step 2 − Break the functionality into smaller componentsThe first Thing React suggest is to create the ... Read More

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 input username.Inheritanceclass UserNameForm extends React.Component { render() { return ( ); } } ReactDOM.render( < UserNameForm />, document.getElementById('root'));This sis simple to just input ... Read More

706 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 in relevant components simultaneously. This is a single source of truth for shared state components.ExampleWe have a App component containing PlayerContent and PlayerDetails component. PlayerContent shows the player name buttons. PlayerDetails shows the details of the in one line.The app component contains the state for both the component. The selected ... Read More

440 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); this.handleFormSubmit = this.handleFormSubmit.bind(this); this.inputUserName = React.createRef(); } handleFormSubmit(event) { console.log('username: ' + this.inputUserName.current.value); event.preventDefault(); } render() { return ( ... Read More

571 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 of map function. Instead of just returning a square number , we will return a list element with value of square.const originalNumbers = [ 2, 4, 6, 8, 10]; const squaredNumbersList= originalNumbers.map((number) => {number*number} );Render on the screen with ui tag −ReactDOM.render( { squaredNumbersList }, document.getElementById('root') );When ... Read More

381 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 is used in above example. Type of user decides which message to return.Local state of component is useful in deciding the conditional rendering as state is flexible to change inside the component.Inline if with logical && operatorfunction MessageSizeChecker(props) { const message = props.message; return ( ... Read More

577 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 we do not write return false to prevent default behavior in React. Instead of that we specifically write event.preventDefault()ExampleIn simple Html − Add User In React it will be written as −function addUser(event){ event.preventDefault(); console.log(‘Add user event clicked’); } Add User Here event passed in ... Read More

433 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 can be changed by user actions and adds dynamism to UI. Updating the data from server with the use of state is common use case.Difference between state and props −As we know props is a properties JavaScript object which hold information passed as an attribute to the component.Props value are ... Read More

291 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 has a return statement in function and Stateful component has a render method which returns react elements.Simple react element to display on the page is −const message=Hello; ReactDOM.render( message, document.getElementById(‘root’) );It displays the Hello message on the screen.Creating a functional component −function Message(props){ return ( ... Read More