I'm trying to push the values in the input field to the firebase app. I have managed to fetch data from it but i can't seem to understand the submit function. I feel like i'm missing something really simple. When i try to use savePost it says it's not a function.
the action is:
export function savePost(post) {
return dispatch => database.push(post)
}
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { savePost } from '../actions/index';
class AddPost extends Component {
constructor(props) {
super(props);
this.state= {
title: '',
body: ''
}
this.onChangeTitle = this.onChangeTitle.bind(this)
this.onChangeBody = this.onChangeBody.bind(this)
this.onSubmit = this.onSubmit.bind(this)
}
onChangeTitle(e){
this.setState({
title: e.target.value,
})
}
onChangeBody(e){
this.setState({
body: e.target.value,
})
}
onSubmit(e, values) {
e.preventDefault();
savePost(this.state)
}
render() {
return (
<div className="container">
<form onSubmit={this.onSubmit.bind(this)}>
<input value={this.state.title} onChange={this.onChangeTitle} type="text" name="title" />
<input value={this.state.body} onChange={this.onChangeBody} type="text" name="body"/>
<button type="submit">Post</button>
</form>
</div>
);
}
}
const mapDispatchToProps = dispatch => ({
savePost: dispatch(savePost())
});
export default connect(undefined, mapDispatchToProps)(AddPost);
configureStore.jsorstore.jslooks like?this.props.savePost