Start a Project

Passing Information From Java to JavaScript in React Native

In this blog, we will learn about passing Information from Java to JavaScript in our React Native Application.

Well, react native has a huge community and makes everything easy especially for cross-platform developments (both Android & iOS).

As a result, most of the problems a beginner developer will face have already been posted and resolved over the internet.

But sometimes we just want to do a few things in the Android Code and then pass on this to the javascript.

Let’s see how we can do this

APPROACH:

CODE :

First, we will just have a look at the Android Side Changes

Let’s just say I want to Transfer a String to javascript code from our MainActivity.

With this, you are able to emit an event from your native java to javascript.

But Still, you will not be able to receive this event in your javascript code as you have not subscribed to this event.

So, now let’s just have a look at the javascript side changes you need to make.

Let’s say I want to receive this event in my App.js file.

Key Points to Understand

Java KeyPoints
JavaScript KeyPoints
Common Mistakes during Implementation

 

Hope this helps you.

Keep coding and Keep Sharing 🙂

References : 1) https://facebook.github.io/react-native/docs/native-components-android#events

2) https://levelup.gitconnected.com/react-native-events-in-gory-details-what-happens-on-the-way-to-listeners-2cee6c55940c

 

Exit mobile version