简体   繁体   中英

React caching rendered components

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?

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);
        });
    }
}

I currently really need this feature.

Does someone knows of it's possible to implement it with react hooks?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM