componentDidMount(){ let dispatch = store.dispatch dispatch(fetchPosts()) .then( (posts) => { this.setState({ posts: posts }) }) }
handleSubmit(data){ console.log('data from post form: ' + JSON.stringify(data)) this.setState({ type: 'info', message: 'Sending info ...' }); let dispatch = store.dispatch dispatch(createPost(data)) .then( () => { browserHistory.push('/home') }) }
firebase.auth().onAuthStateChanged((user) => { if (user) { store.dispatch(login(user.uid)); store.dispatch(startSetExpenses()).then(() => { renderApp(); if (history.location.pathname === '/') { history.push('/dashboard'); } }); } else { store.dispatch(logout()); renderApp(); history.push('/'); } });
function app([push]) { const store = createStore( rootReducer, composeEnhancers( applyMiddleware(thunkMiddleware), applyMiddleware(samplePlayerMiddleware), persistState('entities', { key: 'push-with-react' }) ) ) push.clearLCD() store.dispatch(init()) .then(() => { ReactDOM.render( <Provider store={store}> <App push={push} /> </Provider>, document.getElementById('app') ) }) }
//init data store.dispatch(todoActions.loadInitTodos()).then(function () { var contentHtml = React.renderToString( <Provider store={store}> {function () { return <TodoApp />; }} </Provider> ); var initialState = JSON.stringify(store.getState()); res.render('index.ejs', {contentHtml: contentHtml, initialState: initialState}); }).catch(function(error){ res.json({errMsg: 'internal error'}) });
handleCommentSubmit(data, postId){ // make post comment request, receive post and update list of posts data.postId = postId let dispatch = store.dispatch dispatch(commentPost(data)) .then( (updatedPost) => { if(updatedPost.hasOwnProperty('error')){ alert('error replying to post') }else{ // set state to current post let newPosts = this.state.posts.map( post => { if(post._id != updatedPost._id) return post else return updatedPost }) this.setState({ posts: newPosts }) } }) }