React Native - Appregistry.registerComponent with Provider

Asked

Viewed 219 times

0

I would like to know why when I use the Preview like this

//Root.js
import React from 'react';
import { combineReducers, createStore, applyMiddleware } from "redux"
import { listaDesejosList, listaDesejosEdit } from "./src/reducers/reducers"
import customMiddleware from "./src/commons/custom-middleware"
import App from "./App"
import { Provider } from 'react-redux';

const rootReducer = combineReducers({
    listaDesejos: listaDesejosList,
    desejo: listaDesejosEdit
})
export const store = createStore(rootReducer, applyMiddleware(customMiddleware))

const Root = () => {
    return (
        <Provider store={store}>
            <App />
        </Provider>
    )
}
export default Root;

And I try to use in registerComponent so:

//index.js
import { AppRegistry } from 'react-native';
import Root from './Root';
import { name as appName } from './app.json';
AppRegistry.registerComponent(appName, <App/>);

This error occurs

could not find react-redux context value; please ensure the component is wrapped in a `<Provider>`

I ask because I am making an app in reactjs and React Activate and I would like to keep a certain standard in the code

1 answer

0


Iae, I have a code ready and it works perfectly.

import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import reducers from './store/reducers/index';
import Navigation from './Navigation'

class App extends Component {
    render() {
        const store = createStore(reducers, {}, applyMiddleware(ReduxThunk))
        return (
            <Provider store={store}>
                <Navigation />
            </Provider>
        )
    }
}

export default App;

And in my index.js I call as follows.

import React from 'react'
import {AppRegistry} from 'react-native';
import {name as appName} from './app.json';
import App from './app/App';

const MyApp = props => (
    <App />
)

AppRegistry.registerComponent(appName, () => MyApp)

My reducers and my actions are in another folder, to make it more organized.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.