ReactJS

ReactJs - Using single state object to handle multiple fields of form

Sometimes you may have seen reactjs form component code where a separate state variable is assigned to separate form fields and a separate onChange handler for each form field. There is no harm in this method, but it creates some extra code in your file which could create a future problem in managing the project.

React Native - Using React Navigation

In the Mobile app, we need to navigate between different screens, and each platform has its way of implementation. But in react native, we use the same code base for building a mobile app for all platforms. 

Fortunately, you don't need to write the platform-specific code for creating navigation; it has already been done by someone. We have react-navigation library, which creates navigation for us and handles underlying platform complexities.

Here is a simple example.

Detail Component

ReactJS Context

In ReactJS, if you want to share the data between two or more components, you need to keep that data to their component which is parent component and then you pass that data in the form of properties. If you want to share the same data to further down components, you need to do the same.
Its method is to manage state or data which can be shared among multiple components.
You can pass this data to components without using Props.

Tags

ReactJS - Update state (Complex state) having array values

Normally, state of ReactJS component may have many state properties/constants/variables to hold values after something is done. If state object has one value, than is very easy to update this value using setXXX function. But if the state has Array type values, than you need to merge the values. To merge the values, you need to pull previous values, extract them and create new array using the old values and new value. Then set the new update array back to state.

Tags

ReactJS - Adding reactjs in existing website

1 Create ReactJS app

Create any react app as usual you do. There is nothing special you need to configure to use the react app code in existing website.

2 Add the .env file at the root of this application

This file would contain some configuration values that will be used by build tool.

3 Add the INLINE_RUNTIME_CHUNK=false in .env file

This configuration would allow to create separate packaged code of entire react app at one place.

Tags