React caching rendered components

2019-07-05 04:32发布

Is there any open source code or examples that try to do caching of rendered React components on memcached or something simillar? Anyone that has already dealt with this?

1条回答
The star\"
2楼-- · 2019-07-05 05:11

Like FakeRainBrigand suggested, you can just save the html. However, one neat thing about react is that every component is represented with state/props. This means if you suitably represent your UI with those fields, you should be able to reproduce your page given the same state/props.

This could possibly mean that if you stored the state/props somehow, and loaded it back up, you could effectively "cache" the components for later, and very cheaply at that. I'm thinking something similar to this below:

componentDidMount: function () {
    if(this.props.id) {
        provider.load(this.props.id, function (result) {
            this.setState(result);
        });
    }
}
查看更多
登录 后发表回答