React native 如何使用redux将从服务器获取的数据传递到react native中的多个堆栈外导航器屏幕?

React native 如何使用redux将从服务器获取的数据传递到react native中的多个堆栈外导航器屏幕?,react-native,redux,react-redux,redux-thunk,react-redux-form,React Native,Redux,React Redux,Redux Thunk,React Redux Form,我有一个登录函数,可以从mysql数据库中获取用户信息。我想将这些数据发送到不同的屏幕,其中一些是堆栈外导航器。我研究了一段时间,知道这可以通过redux实现,但我找不到一个明确的例子来说明如何实现这一点。有什么建议吗 这是我的登录功能: login = () => { if (this.state.inputFieldsStatus == true) { // this.setState({passwordError:" So

我有一个登录函数,可以从mysql数据库中获取用户信息。我想将这些数据发送到不同的屏幕,其中一些是堆栈外导航器。我研究了一段时间,知道这可以通过redux实现,但我找不到一个明确的例子来说明如何实现这一点。有什么建议吗

这是我的登录功能:

login = () => {
    if (this.state.inputFieldsStatus == true)
        {  
            // this.setState({passwordError:" Something went wrong! "})
            fetch('http://ip_Adress/login', {
                method: 'POST', // *GET, POST, PUT, DELETE, etc.
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    email: this.state.email,
                    password: this.state.password,
                })
            })
            .then((response) => response.json())
            .then((res) => {

                // alert(JSON.stringify(res.message));
            
                if (res.success === true ) {
                    // AsyncStorage.setItem('user', res.user);
                    this.props.navigation.navigate('Home', 
                        // {
                        //     screen: 'Messages',
                        //     params: 
                        //         {
                        //             message: res.message,
                        //             otherParam: 'anything you want here'
                        //         } 
                        // },
                        {
                            screen: 'Profile',
                            params: 
                                {
                                    message: res.message,
                                    otherParam: 'anything you want here'
                                } 
                        }
                    );
                } else {
                    this.setState({passwordError: res.message })
                    // alert(res.message);
                }
            })
            .done();
        }
        else 
            {
                // alert(' Please fill in all fields! ');
                this.setState({passwordError:" Please fill in all fields! "})
            }
}

我建议你将数据存储在上下文中。为什么这个问题用redux标记,我没有看到任何代码表明你正在使用redux存储?试试这个@C.K非常感谢:)上下文API解决了你的问题吗@User10我建议你将数据存储在上下文中。为什么这个问题用redux标记,我没有看到任何代码表明你正在使用redux存储?试试这个@C.K非常感谢:)上下文API解决了你的问题吗@用户10