Mehedi Hassan Piash | Senior Software Engineer | Android | iOS | KMP | Ktor | Jetpack Compose | React-Native.

September 29, 2019

Call back function in react-naitve

September 29, 2019 Posted by Piash No comments

How to send data current page to previous page using callBack in react - native.

import React, {  Component} from 'react';
import { Text, TouchableOpacity} from 'react-native';
import {Actions} from 'react-native-router-flux';

export default class FirstScreen extends Component {
    constructor(props) {
        super(props);
    }
    onCallBack(data) {
        console.log(data);
    }
    render() {
        return (
<TouchableOpacity
        onPress = {  () => {
                    Actions.SecondScreen({
                        onCallBack: this.onCallBack.bind(this)
                    });
                }
            } >
            <Text > SecondScreen < /Text>         
 </TouchableOpacity >
        );
    }
}
###############-- -- -- -- -- -- -- -- -- -- -- - ########################
import React, { Component} from 'react';
import {  Text,TouchableOpacity} from 'react-native';
import { Actions} from 'react-native-router-flux';

export default class SecondScreen extends Component {
    constructor(props) {
        super(props);
    }
    render() {
        return (
< TouchableOpacity
         onPress = { () => {
                    this.props.onCallBack('data of previous screen')
                    Actions.pop()
                }
            } >
            <Text > BackToScreen < /Text>       
   </TouchableOpacity > );

    }
}

0 comments:

Post a Comment