in Education by
I am using Firebase authentication and react-redux in my app. I added firebase.auth().onAuthStateChanged to my App.js's componentDidMount function to check for user login status throughout the app. I tried connecting App.js to my redux actions's function getUserProfile like this: App.js import React from 'react'; import { createStackNavigator, createAppContainer } from 'react-navigation'; import { Provider } from 'react-redux'; import { createStore, applyMiddleware } from 'redux'; import reducers from './app/src/reducers'; import ReduxThunk from 'redux-thunk'; import { connect } from 'react-redux'; import { firebase } from './config/config'; import { getUserProfile } from './app/src/actions/index'; ... const AppContainer = createAppContainer(MainStack); class App extends React.Component { constructor(props) { super(props); } componentDidMount = () => { var that = this; firebase.auth().onAuthStateChanged(async function(user) { if (user) { await that.getUserProfile(user.uid); } else { that.navigation.navigate('Auth'); } }) } render() { const store = createStore(reducers, {}, applyMiddleware(ReduxThunk)); return ( ); } } const mapStateToProps = state => { return { user: state.auth.user } } export default connect(mapStateToProps, {getUserProfile})(App); I got the error: Invariant Violation: Could not find "store" in the context of "Connect(App)". Either wrap the root component in a , or pass a custom React context provider to and the corresponding React context consumer to Connect(App) in connect options. How do I fix this? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I see the problem now. You are using connect on a component that is the parent of the Provider component. What you need to do is create a new component called Main and use connect on that. Your App component cannot use connect because it is not a child of Provider, instead it is the parent. Or in other words: App.js import React from 'react'; import { Provider } from 'react-redux'; import { createStore, applyMiddleware } from 'redux'; import reducers from './app/src/reducers'; import ReduxThunk from 'redux-thunk'; ... const store = createStore(reducers, {}, applyMiddleware(ReduxThunk)); class App extends React.Component { render() { return (
); } } export default App; Main.js import React from 'react'; import { createStackNavigator, createAppContainer } from 'react-navigation'; import { connect } from 'react-redux'; import { firebase } from './config/config'; import { getUserProfile } from './app/src/actions/index'; ... const AppContainer = createAppContainer(MainStack); class Main extends React.Component { constructor(props) { super(props); } componentDidMount = () => { var that = this; firebase.auth().onAuthStateChanged(async function(user) { if (user) { await that.getUserProfile(user.uid); } else { that.navigation.navigate('Auth'); } }) } render() { return ( ); } } const mapStateToProps = state => { return { user: state.auth.user } } export default connect(mapStateToProps, {getUserProfile})(Main);

Related questions

0 votes
    I am using Firebase authentication and react-redux in my app. I added firebase.auth().onAuthStateChanged to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have an application I'm building with Firebase. Essentially, I'm trying to build an authentication system ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    My code: PhoneAuthProvider.getInstance().verifyPhoneNumber( phoneNumber, // Phone number to verify 60, // Timeout ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    This is part of the component : import MyComp from '../../lib/MyComp' const Data = ( { data } ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    This is part of the component : import MyComp from '../../lib/MyComp' const Data = ( { data } ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I'm new to React with Redux and I've been working on a new web application that has some basic ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is Redux react interview questions? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    I am getting the error 'Uncaught TypeError: firebase.auth is not a function'. My code was working perfectly ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Hi I know it's a known issue about the auto height of webview in react native, and I have tried ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I have to download images to my iOS apps local file system and read them back. On my simulator I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 6, 2022 in Education by JackTerrance
0 votes
    Hello All,I am using react-navigation v3 for navigation purposes.I have created a tab navigator called ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 30, 2022 in Education by JackTerrance
0 votes
    Warning: Possible Unhandled Promise Rejection (id: 0) TypeError: Object is not a function (evaluating ' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    This problem is only appearing on iOS. The application is built with react-native 0.57.7 and on ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    my AndroidManifest.xml looks like this: and I get this error: * What went wrong: Execution failed for ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
...