反应缓存渲染的组件 [英] React caching rendered components

查看:70
本文介绍了反应缓存渲染的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何开源代码或示例试图在memcached或类似的东西上缓存渲染的React组件?
任何已经处理过这个的人?

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?

推荐答案

像FakeRainBrigand建议的那样,你可以保存html。然而,关于反应的一个巧妙的事情是每个组件都用state / props表示。这意味着如果您使用这些字段适当地表示您的UI,您应该能够在给定相同状态/道具的情况下重现您的页面。

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

这篇关于反应缓存渲染的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆