Skip to main content

REACTJS FOR BEGINNERS | A STEP BY STEP APPROACH

There are many problems while building large applications with data that changes over time. To solve this ,I suggest checking out ReactJS. React lets you express how your app should look at any given point, and can automatically manage all UI updates when your underlying data changes.
React is one of the most popular JavaScript front end libraries which is developed by Facebook. It’s used for handling view layer for web and mobile apps. The main feature of ReactJS is that it allows us to create reusable UI components.  The syntax used in React is JSX which allows you to mix HTML with JavaScript. This is not a requirement – you can still write in plain JavaScript. But this is suggested because this makes writing your components a breeze.

Installation

To install React with Yarn, run:
To install React with npm, run:
The bundlers like webpack or Browserify is recommended. So you can write modular code and bundle it together into small packages to optimize load time.
Use React with Babel to let you use ES6 and JSX in your JavaScript code. ES6 is a set of modern JavaScript features that make development easier.  JSX is an extension to the JavaScript language that works nicely with ReactJS.

React is efficient

ReactJS creates its own virtual DOM where your components actually live. It calculates what changes need to be made in the DOM beforehand and updates the DOM tree accordingly. So it is flexible and gives amazing gains in performance. It can be used on client and server side. This way, React avoids costly DOM operations and makes updates in a very efficient manner.
The smallest ReactJS example looks like this:
It renders a header saying “Hello, World!” on the page. You can see the demo here.

React Features

Components are the heart and soul of ReactJS. You need to think of everything as a component. This is why it is helpful to maintain the code when working on larger scale projects. The one way data flow in react makes it easy to reason about your app. “Flux” is a pattern that helps keeping your data unidirectional. Components accept arbitrary inputs called “props” and return React elements describing what should appear on the screen.
Create a new component class using component class approach. Components have one requirement, they must implement render function that tells the component what to render. You can see the demo here.

States in React

State is the place where the data comes from. You should always try to make your state as simple as possible and minimize number of stateful components.
Now this will render the function. You can see the demo here.
The key difference between props and state is that state is internal and controlled by the component itself while props are external and controlled by whatever renders the component. To access a component’s state, use “this.state” , just like how we use “this.props” . To update a component’s state, call “this.setState” with an object map of keys to updated values.

Component lifecycle

Lifecycle methods are  special methods that automatically get called as our component goes about its business. Each component has several “lifecycle methods” that you can override to run code at particular times in the process.

getInitialState()

This method is invoked once, right before the mounting phase.  The return value of this method will be used as initial value of this.state and should be an object.

getDefaultProps()

This can be used to define any default props which can be accessed via this.props.

componentWillMount()

This is the last method that gets called before your component gets rendered to the DOM. If you were to call “setState” inside this method, your component will not re-render.

componentDidMount()

This function is called as the render method has been executed. This method is the best place for initializing other Javascript libraries that need access to the DOM and for data fetching operations.

shouldComponentUpdate() 

This method allows you to control the updating behavior. If you use this method and return a true value, the component will update. If this method returns a falsevalue, this component will skip updating.

componentWillReceiveProps()

This is only called when the props have changed and we can use this method as an opportunity to react to a prop transition before the render() method is called.

componentWillUpdate()

This gets called  just before your component is about to update.

componentDidUpdate()

Finally this is called after the render method. This method can be used to perform DOM operations after the data has been updated.

React is a Javascript library which allows developers to create fast user interfaces. React views are typically rendered using components that contain additional components specified as custom HTML tags. One of the unique features of ReactJS is not only it can perform on the client-side, but it can also be rendered on the server-side, and they can work together.
It also uses the concept called Virtual DOM, creates an in-memory data structure cache, enumerates the resulting differences, and then updates the browser’s displayed DOM efficiently. That is the react libraries only renders the sub-components that have been modified. So this makes it faster and efficient.

References


Comments

Post a Comment

Popular posts from this blog

ACP Exam tips

       1.    Time: The 3 hours to answer 120 questions were sufficient. I finished answering all questions in 2 hours. There were 4-5 questions not framed well (poor English). I spend 1 hr to review all my answers again. 2. Agile Practices: There were multiple questions on SCRUM and XP, very few questions on Kanban and Lean, almost none on Crystal, FDD, and DSDM. 3. Roles: Completely Understand the Roles in SCRUM and XP, what are the responsibilities carried by those roles, various meetings, input and outcome of those meetings like review, retrospective etc, 4. Scenario Based Questions: There were multiple questions based on scenarios and how best will you apply agile practices under those scenarios. Mostly on Team,Scrum,Communication stuff. 5. Completely understand the when and what use of Scrum Artifacts and ceremony. 6. . Many questions on team Collaboration, Risk,Velocity. 7. Few Question on EVM,EV,PV (no calculation). 8. Multiple quest...

The advantage of ReactJs:

SEO-friendly:  ReactJs is very comfortable with the SEO. You can easily run your ReactJs with the servers while other Javascript doesn’t support SEO. JSX : In ReactJs for templating we use JSX. JSX is simple JavaScript which allows HTML syntax and other HTML tags in the code. HTML syntax is processed into javascript calls of React framework. React Native:  It contains a native library which supports Native iOS, Android application. Simplicity : It is a very simple to grab. Its component-based approach and well-defined lifecycle are very simple to use. Easy to learn:  Anyone with the basic knowledge of programming can easily ReactJs. For Learning ReactJs you just need to know the basics for HTML and CSS. Data-Binding:  ReactJs uses one-way data binding and application architecture controls the flow of data via a dispatcher. Testability : ReactJs application is very easy to test. Its views are very easy to configure and can be treated as the a...

PMI Agile Certified Practitioner (PMI-ACP®) Certificate

This post is for  Project Management Institute (PMI)’s Agile Certified Practitioner(PMI-ACP) Certificate . Exam for this certificate is meant to test skills of agile practitioners.  Pre-requisite  for appearing in the exam includes having prior experience in general project management (2000+ hours) and agile specific project management (1500+ hours). Folks having prior  PMP ®  or PgMP ®  automatically satisfy general project management experience and hence need not elaborate the experience while filling the form. Also pre-requisite requires having 21 contract hours earned in agile practice, which could include imparting or participating in agile training [Certified Scrum Master (CSM®), In-house agile training, Coaching Client, etc.] My experience of the exam includes following tips 1. This exam tests knowledge on tools, techniques, processes, artifacts, etc. of those practicing agile. It includes knowledge on Scrum, XP, Kanban & L...