I want to change value dynamically at some event
Event:
BackgroundGeolocation.on(\'location\', (location) => {
currentDistance = distance(
Below is the example where it uses states for dynamic changing of text value while clicking on it. You can set on any event you want.
import React, { Component } from 'react'
import {
Text,
View
} from 'react-native'
export default class reactApp extends Component {
constructor() {
super()
this.state = {
myText: 'My Original Text'
}
}
updateText = () => {
this.setState({myText: 'My Changed Text'})
}
render() {
return (
{this.state.myText}
);
}
}
EDIT: Using React Hooks
import React, { useState } from 'react';
import { View, Text } from 'react-native';
const ReactApp = () => {
const [myText, setMyText] = useState("My Original Text");
return (
setMyText("My Changed Text")}>
{myText}
)
}
export default ReactApp;