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