当我学习反应原生时,我得到错误
'标题'找不到
但我定义了标题。
import React,{Component} from 'react';
import {View,Text,StyleSheet,TextInput} from 'react-native';
import SubmitButton from './SubmitButton';
import {white,black,gray} from '../utils/colors';
import {saveDeckTitle} from '../utils/api';
import {addDeck} from '../Actions';
import {connect} from 'react-redux';
class NewDeck extends Component{
state={
title:''
};
submit=()=>{
const {title}=this.state;
saveDeckTitle(title);
this.props.dispatch(addDeck(title));
};
render(){
return (
<View style={styles.container}>
<Text style={styles.question}>What is the title of your new
deck?</Text>
<Text style={{marginTop:50,alignSelf:'flex-
start',fontSize:20}}>Deck Title</Text>
<TextInput
style={styles.textInput}
onChangeText={(title) => {this.setState({title})}}
value={this.state.title}
placeholder='Deck Title'
placeholderTextColor={gray}
underlineColorAndroid={gray}
keyboardType="default"
/>
<Text style={{height:200}}/>
<SubmitButton style={styles.submitBtn} onPress=
{this.submit}>Submit</SubmitButton>
<Text>{this.state.title}</Text>
</View>
)
}
}
行动中:
export const ADD_DECK='ADD_DECK';
export function addDeck(title) {
return {
type:ADD_DECK,
title
}
这样的错误:
无法找到变量:&#39; title&#39;
当我没有添加'this.props.dispatch(addDeck(title));'
时效果很好,我想知道为什么我得到此错误