Redux: Displaying time?

Created on 20 Sep 2015  路  2Comments  路  Source: reduxjs/redux

I have a lot of components that update every seconds based on Date.now(). However, performing these updates through the redux stores makes dev-tools and logging extremely slow, spammed and unusable.

Does anyone have any suggestions on how one can handle this in the best way?

One way I was thinking about was that the components themselves have a time subscription that calls setState with the current time, i.e. time updates are local to the component. The time has (mostly) no logical meaning only visual.

question

Most helpful comment

How are you using time in your reducers? Since time is an external state, and introduces non-pure effects into store, it should probably be kept external. If you're using React, I would handle it internal to your components.

Say, for example, you have a list of comments on a blog and you want to have the timestamp next to each comment update in real time ("1 minute ago" changes to "2 minutes ago", etc.). I wouldn't track that in my redux store, as that's a display concern. I would either have each comment component set up a setInterval and re-render as needed. Or I would set that up at the top level comment list container and pass down the current time as a prop to each comment component and have them re-render as needed.

All 2 comments

How are you using time in your reducers? Since time is an external state, and introduces non-pure effects into store, it should probably be kept external. If you're using React, I would handle it internal to your components.

Say, for example, you have a list of comments on a blog and you want to have the timestamp next to each comment update in real time ("1 minute ago" changes to "2 minutes ago", etc.). I wouldn't track that in my redux store, as that's a display concern. I would either have each comment component set up a setInterval and re-render as needed. Or I would set that up at the top level comment list container and pass down the current time as a prop to each comment component and have them re-render as needed.

Sounds reasonable. Thank you for the feedback.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiyinyiyong picture jiyinyiyong  路  52Comments

erikras picture erikras  路  63Comments

mordrax picture mordrax  路  51Comments

gaearon picture gaearon  路  61Comments

markerikson picture markerikson  路  51Comments