我已经在我的PState接口中定义了我的动作,但是它仍然不会获取我的数据。在常规的javascript中,这可以正常工作,但我无法将其转换为打字稿。我不知道我的IProps界面出了什么问题。我的动作有问题吗?
export const addNote = (values) => {
return (dispatch) => {
console.log('these are the values', values);
const firestore = firebase.firestore();
const notesRef = firestore.collection('notes');
notesRef.add(values);
dispatch({type: ADD_NOTE, payload: values});
}
}
import React, {Component} from 'react';
import { addNote } from './actions/noteAction';
import { connect } from 'react-redux';
class Form extends Component<IProps, IState>{
constructor(props: IProps) {
super(props);
this.state = {
note: ''
};
}
onSubmit(e: any){
e.preventDefault()
const noteData = {
note: this.state.note
}
console.log(noteData);
this.props.addNote(noteData);
}
render(){
return(
<div>
<form onSubmit={this.onSubmit.bind(this)}>
<input
name="note"
placeholder="note"
value={this.state.note}
onChange={(e) => this.setState({note: e.target.value})}
/>
<input type="submit"/>
</form>
</div>
);
}
}
interface IState {
note: string
}
interface IProps{
addNote: any
}
export default connect(null, addNote)(Form);