Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 期望减速器是一个函数_Javascript_React Native_Redux_React Redux - Fatal编程技术网

Javascript 期望减速器是一个函数

Javascript 期望减速器是一个函数,javascript,react-native,redux,react-redux,Javascript,React Native,Redux,React Redux,我创建了一个新的react本机项目,并编写了一个redux demo.IOS模拟器来显示错误“期望减速机是一个函数”。我试图从预览答案中解决这个问题,但它不起作用 index.ios.js import React, {Component} from 'react'; import {AppRegistry, StyleSheet, Text, View} from 'react-native'; import {createStore} from 'redux'; import {Provi

我创建了一个新的react本机项目,并编写了一个redux demo.IOS模拟器来显示错误“期望减速机是一个函数”。我试图从预览答案中解决这个问题,但它不起作用

index.ios.js

import React, {Component} from 'react';
import {AppRegistry, StyleSheet, Text, View} from 'react-native';

import {createStore} from 'redux';
import {Provider} from 'react-redux';
import {reducers} from './src/reducer';
import {App} from './src/App';

const store = createStore(reducers)

export default class rnredux extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Provider store ={store}>
          <App/>
        </Provider>
      </View>

    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
});

AppRegistry.registerComponent('rnredux', () => rnredux);
myComponent.js

import React,{Component} from 'react';
import {Text,TextInput} from 'react-native';

export default class myComponent extends Component{
    render(){
        <View>
            <Text>{this.props.text}</Text>
            <TextInput defaultValue = {this.props.name} onChangeText = {this.props.onChange}></TextInput>
        </View>
    }
}
改变


导入模块的默认值时,不要使用大括号
{}

请解释一下{reducers}和reducers之间的区别。虽然它对我有效,但我还是想知道。@Vijender Kumar的
减缩器
用于导入使用关键字
default
的函数或变量。模块导出时,
{reducers}
用于导入其他函数。默认函数类似于nodejs中的
模块。导出
,其他没有
默认值的函数类似于
导出
import React,{Component} from 'react';
import {Text,TextInput} from 'react-native';

export default class myComponent extends Component{
    render(){
        <View>
            <Text>{this.props.text}</Text>
            <TextInput defaultValue = {this.props.name} onChangeText = {this.props.onChange}></TextInput>
        </View>
    }
}
import {combineReducers} from 'redux';

const reducerAction = (state = {
  text: '你好,访问者',
  name: '访问者'
}, action) => {
  switch (action.type) {
    case 'change':
      return {
        name: action.payload,
        text: '你好,' + action.payload
      };
    default:
      return state;
  }
}

const reducers = combineReducers({
    reducerAction
})

export default reducers;
import {reducers} from './src/reducer';
import {App} from './src/App';
import reducers from './src/reducer';
import App from './src/App';