JavaScript for WordPress Forums React Explained Refactoring stage issues Reply To: Refactoring stage issues

#107515
GPorter43
Participant

If i try to create a new post on save i get the error message

×
Error: Reference.push failed: first argument contains undefined in property ‘posts.slug’
▶ 6 stack frames were collapsed.
AppService.savePost
C:/Users/gport/Desktop/React-Practice/react-project/src/appService.js:41
38 | };
39 |
40 | savePost = post => {
> 41 | return firebase
| ^ 42 | .database()
43 | .ref(“posts”)
44 | .push({
View compiled
App._this.addNewPost
C:/Users/gport/Desktop/React-Practice/react-project/src/App.js:50
47 | .catch(error => console.error(error));
48 | };
49 | addNewPost = post => {
> 50 | this.props.appService.savePost(post);
| ^ 51 | this.displayMessage(“saved”);
52 | };
53 | updatePost = post => {
View compiled
PostForm._this.handleAddNewPost
C:/Users/gport/Desktop/React-Practice/react-project/src/components/PostForm.js:33
30 | if (this.props.updatePost) {
31 | this.props.updatePost(this.state.post);
32 | } else {
> 33 | this.props.addNewPost(this.state.post);
| ^ 34 | }
35 | this.setState({ saved: true });
36 | } else {
View compiled
▶ 20 stack frames were collapsed.
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.