作者: 清仔 時間: 2018-7-15 21:25 標題: React container component pattern 問題
本帖最後由 清仔 於 2018-7-15 21:30 編輯
I have an app structure like this with redux:
app
|-router
| — dashboard container
| — — dashboard component
| — setting container
| — — setting component
Consider the two containers, if I need to get translation text from the store which way should I used?
(1) Connect to redux store on router and pass down to containers by props
(2) Each of the container connect to redux store individually
作者: kc2wong 時間: 2018-7-16 00:14
用context API 得唔得?我會盡量避免唔用redux
作者: 清仔 時間: 2018-7-16 15:59
回覆 2# kc2wong
This is a question of the Container-component pattern.
作者: 七彩小生 時間: 2018-7-16 22:04
好深奧


作者: 清仔 時間: 2018-7-17 09:52
Someone ans me
https://stackoverflow.com/questi ... from-props/51349061
作者: 梁炳 時間: 2018-7-18 13:47
translation text用static resource唔得?
用setTimeout force reload一次就ok
作者: 高原熊 時間: 2018-7-18 17:18
本帖最後由 高原熊 於 2018-7-18 17:22 編輯
del....
作者: 清仔 時間: 2018-7-18 22:39
回覆 6# 梁炳
yes, but not the point I want to discuss in this question
作者: 梁炳 時間: 2018-7-19 00:15
本帖最後由 梁炳 於 2018-7-19 00:16 編輯
Redux connect to whatever components that make sense to connect to, if the component need to display User info, connect to redux
The container does not need to connect to redux if it has nothing to do with the data (e.g. purely for layout purpose)
When you are writing a component, think about how it will be used, does it make sense for the "user" component pass down the data as props to this component. Ask yourself this, you will have an answer
don't think about performance until you face serious problem, but always keep in mind the basic principles to avoid re-rendering too often

