Using Javascript Symbols in React.js Applications

Using Javascript Symbols in React.js Applications

A use case for Javascript Symbols in React.js Applications. One feature that was part of ES6 release was the Symbol data structure. In this article, I am going to talk through a scenario where I felt Symbol can be a best fit.

A use case for JavaScript symbols in React.js applications

One feature that was part of ES6 release was the Symbol data structure — but many developers are not aware of its use cases in application code. In this article, I am going to talk through a scenario where I felt Symbol can be a best fit.

Recently, I was working on a feature where we had nested form components that need to be reset or validated from parent component. Initially, I thought of doing it by passing a boolean value as a prop to child components from parent component by setting it to true and then resetting it after the validation is complete to make it ready for the next iteration if we ever want to validate/reset the form again.

So, a simple pseudo code looks like this:

Image for post

Triggering change detection to run validation in child component from parent component

In parent component, we are setting validate value to true first and then resetting it to false . In child component, we are looking for the validate value to run our validation logic. But as you notice, we have to reset validate flag every time after we are done with the validation in order to run the validation afterwards.

So, why do we have to do that? The answer to this questions relates to how change detection runs. In react, like many modern frameworks, one of the ways the change detection process run is when a prop value changes in a component. If that value is a primitive type, it compares the previous value with current value where as in for objects, it checks the reference.

react javascript es6 programming developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

Hire Dedicated React Native Developer

Have you ever thought of having your own app that runs smoothly over multiple platforms? React Native is an open-source cross-platform mobile application framework which is a great option to create mobile apps for both Android and iOS. **[Hire...

Hire Dedicated React Native Developer in India | React Native Development

Hire dedicated React Native developers for your next project. As the top react native development company we offer you the best service as per your business needs.

Hire React Js Developer from Expert React JS Development Company

Are you looking to [hire React JS developer](https://www.mobiwebtech.com/react-js-development-company/ "hire React JS developer") from a prestigious and reliable React JS development company? Visit at Mobiweb Technologies here we have a big team...

A Short Guide to React Native App Development

React Native is undoubtedly one of the most widely used cross-platform frameworks for creating native-like apps. This framework can be easily used for developing brand-new apps from scratch and even in existing iOS or Android projects.easily used for developing brand-new apps from scratch and even in existing iOS or Android projects.