最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding Redux Provider store to the main index file in React - Stack Overflow

programmeradmin0浏览0评论

I was thinking about passing my <Provider store={Store}> directly to my main index.js file:

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

AppRegistry.registerComponent(appName, () => App);

I mean, I know we can always do something like this in our App.js :

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Provider } from 'react-redux';
import Store from "./src/store.js"  
import Something from './src/container/Something.js';

export default class App extends React.Component {
  render() {
    return (
      <Provider store={Store}>
        <Something />     
      </Provider>
    );
  }
}

I was wondering if we can do it in Index.js, and if so then how?

I was thinking about passing my <Provider store={Store}> directly to my main index.js file:

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

AppRegistry.registerComponent(appName, () => App);

I mean, I know we can always do something like this in our App.js :

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Provider } from 'react-redux';
import Store from "./src/store.js"  
import Something from './src/container/Something.js';

export default class App extends React.Component {
  render() {
    return (
      <Provider store={Store}>
        <Something />     
      </Provider>
    );
  }
}

I was wondering if we can do it in Index.js, and if so then how?

Share Improve this question edited Jan 10, 2024 at 16:57 Drew Reese 203k17 gold badges235 silver badges266 bronze badges asked Sep 13, 2018 at 13:06 AlwaysblueAlwaysblue 11.8k44 gold badges139 silver badges252 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 34

On index.js you could create another component wrapping App:

import {AppRegistry} from 'react-native';
import App from './App';
import React from 'react';
import {Provider} from 'react-redux';
import Store from "./src/store.js"  
import {name as appName} from './app.json';

const Root = () => (
  <Provider store={store}>
    <App />
  </Provider>
)

AppRegistry.registerComponent(appName, () => Root);
发布评论

评论列表(0)

  1. 暂无评论