Javascript <;供应商>;不支持动态更改'store'
我最近开始学习如何同时使用React Native和Redux。我在IOS模拟器中遇到了一个错误,我不知道如何修复,我想知道以前是否有人见过这个错误 以下是错误: 提供程序不支持动态更改存储。您很可能会看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,不再自动热加载减速器。有关迁移说明,请参见 我遵循了错误消息中提到的链接,但它似乎需要我使用Webpack。在链接中,它引用了Javascript <;供应商>;不支持动态更改'store',javascript,react-native,redux,Javascript,React Native,Redux,我最近开始学习如何同时使用React Native和Redux。我在IOS模拟器中遇到了一个错误,我不知道如何修复,我想知道以前是否有人见过这个错误 以下是错误: 提供程序不支持动态更改存储。您很可能会看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,不再自动热加载减速器。有关迁移说明,请参见 我遵循了错误消息中提到的链接,但它似乎需要我使用Webpack。在链接中,它引用了if(module.hot),我在尝试使用此解决方案时遇到以下错误: 无法解析模块 所以我不知
if(module.hot)
,我在尝试使用此解决方案时遇到以下错误:
无法解析模块
所以我不知道接下来该怎么办。到目前为止,我的项目非常小。我有我的index.ios.js
,然后是一个包含组件文件夹、商店文件夹和reducer文件夹的应用程序文件夹。结构如下所示:
- index.ios.js
- 应用程序
- 贮藏
- index.js
- 组成部分
- index.js
- 减速器
- index.js
- 贮藏
index.ios.js
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import {configureStore} from './app/store';
import Main from './app/components/Main';
export default class introToRedux extends Component {
render() {
return (
<Provider store={configureStore()}>
<Main />
</Provider>
);
}
}
AppRegistry.registerComponent('introToRedux', () => introToRedux);
import React, { Component } from 'react';
import {connect} from 'react-redux';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
var Main = React.createClass({
render(){
return (
<View>
<Text>{this.props.text}</Text>
</View>
);
}
});
var mapStateToText = (state) => {
return {
text: state.text
}
}
module.exports = connect(mapStateToText)(Main);
module.exports = (state={}, action) => {
switch (action.type) {
default:
return state;
}
}
import {createStore} from 'redux';
import reducer from '../reducer';
var defaultState = {
text: "default text"
}
export var configureStore = (initialState=defaultState) => {
return createStore(reducer, initialState);
}
reducer/index.js
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import {configureStore} from './app/store';
import Main from './app/components/Main';
export default class introToRedux extends Component {
render() {
return (
<Provider store={configureStore()}>
<Main />
</Provider>
);
}
}
AppRegistry.registerComponent('introToRedux', () => introToRedux);
import React, { Component } from 'react';
import {connect} from 'react-redux';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
var Main = React.createClass({
render(){
return (
<View>
<Text>{this.props.text}</Text>
</View>
);
}
});
var mapStateToText = (state) => {
return {
text: state.text
}
}
module.exports = connect(mapStateToText)(Main);
module.exports = (state={}, action) => {
switch (action.type) {
default:
return state;
}
}
import {createStore} from 'redux';
import reducer from '../reducer';
var defaultState = {
text: "default text"
}
export var configureStore = (initialState=defaultState) => {
return createStore(reducer, initialState);
}
store/index.js
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import {configureStore} from './app/store';
import Main from './app/components/Main';
export default class introToRedux extends Component {
render() {
return (
<Provider store={configureStore()}>
<Main />
</Provider>
);
}
}
AppRegistry.registerComponent('introToRedux', () => introToRedux);
import React, { Component } from 'react';
import {connect} from 'react-redux';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
var Main = React.createClass({
render(){
return (
<View>
<Text>{this.props.text}</Text>
</View>
);
}
});
var mapStateToText = (state) => {
return {
text: state.text
}
}
module.exports = connect(mapStateToText)(Main);
module.exports = (state={}, action) => {
switch (action.type) {
default:
return state;
}
}
import {createStore} from 'redux';
import reducer from '../reducer';
var defaultState = {
text: "default text"
}
export var configureStore = (initialState=defaultState) => {
return createStore(reducer, initialState);
}
这方面的任何帮助都会很棒 为什么要导出
configureStore()
?你也可以
const initialState = {
text: "default text"
}
export default function reducer (state=initialState, action) {
switch (action.type) {
default:
return state;
}
}
createStore()
应执行一次
index.js
// import stuff
const store = createStore(reducer)
class IntroToRedux extends Component {
render() {
return (
<Provider store={store}>
<Main />
</Provider>
);
}
}
ReactDOM.render(IntroToRedux, document.getElementById('root'))
//导入内容
const store=createStore(reducer)
类IntroToRedux扩展组件{
render(){
返回(
);
}
}
render(IntroToRedux,document.getElementById('root'))