Comments (10)
Can you share how you able to see this executing twice?
from mern-starter.
@SOSANA just add console.log inside getPosts function. Log message will appear twice.
from mern-starter.
@SoundBot good catch! check this out, seems to be on initial load we get it called twice where as if we route from post view back to main we only have expected results of executing once...
from mern-starter.
@SOSANA Yep. Any ideas how to fix this?
from mern-starter.
@SoundBot this is where the fun begins, fixing this :)
from mern-starter.
The Action fetchPosts is disptached twice that's why getPosts is called twice. I will look into that.
from mern-starter.
In server/util/fetchData.js
do console.log(needs)
we will get Actions.fetchPosts two times. So the problem is in
const needs = components.reduce((prev, current) => {
return (current.need || [])
.concat((current.WrappedComponent ? current.WrappedComponent.need : []) || [])
.concat(prev);
}, []);
Will fix!
from mern-starter.
@SoundBot @mayankchd
/server/util/fetchData.js
export function fetchComponentData(dispatch, components, params) {
const needs = components.reduce((prev, current) => {
console.log('test');
return (current.need || [])
.concat((current.WrappedComponent ? current.WrappedComponent.need !== current.need : []) || [])
.concat(prev);
}, []);
console.log(needs);
const promises = needs.map(need => dispatch(need(params)));
return Promise.all(promises);
}
/server/controllers/post.controllers.js
export function getPosts(req, res) {
Post.find().sort('-dateAdded').exec((err, posts) => {
if (err) {
return res.status(500).send(err);
}
console.log('postTests');
res.json({ posts });
});
}
I noticed that there is only one function call from server, but fetch still shows logging twice
from mern-starter.
Fixed in #80
from mern-starter.
@SoundBot @mayankchd as per my last comment its called once from server from getPost in post.controller, but fetch shows still fetching twice, this for client?
from mern-starter.
Related Issues (20)
- Problem with production mode in server HOT 2
- TypeError: Cannot read property 'table' of undefined HOT 1
- postcss-cssnext is technically deprecated HOT 1
- Upgrading to webpack 4 breaks the mern-starter HOT 1
- Error importing header / footer background image HOT 4
- Deploying the app using PM2 in EC2 HOT 3
- this.props.history is undefined Trying to access history object HOT 2
- Website is lacking pictures HOT 1
- Upgrade to React Router (MERN 2.6) HOT 6
- Add provision for code-splitting as required
- Can't resolve DNS host HOT 2
- The images on mern.io requested from res.cloudinary.com are resulting in 401 errors (and thus aren't successfully loading)
- Error comment in scss file HOT 1
- How to integrate Reactstrap into mern-starter HOT 4
- Code execution continues when it should stop in POST action HOT 1
- 3.0啥时候好呢,我们等的黄瓜菜都凉了! HOT 2
- RESTful MERN in Typescript - A new project other than this one
- MSBuild.exe` failed with exit code: 1
- Grammatical error on Twitter redirecting text 📝
- Alternative to this repo : Mern Starter Project
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mern-starter.