React 中有一个很酷的新特性——Suspense 组件。目前它只官方支持使用 React.lazy 函数创建的组件。但非正式地众所周知,内部 Suspense 组件是通过在渲染树中更深层次地抛出一个 Promise 来触发的,并且有一些库已经采用了这种技术来带来新的酷炫的开发人员体验,例如:
还有一个核心反应包react-cache使用它(当然是非官方的)。
Having all this in mind I'm kinda confused because there is no any mention in React Docs about throwing promises (in other words what triggers Suspense component) but at the same time there are lots of talks and libraries that use it. In twitter discussion dan abramov replied that the API will likely change. But still the situation is confusing.
So the question is: Is it safe to start using this technique in the production? If not, then how can I use libraries (even facebook based) that have already adopted it? Finally, if the API (throwing promises) is the subject to be changed in future, can I be assured that it's just a tiny change that I need to adopt in my own implementation?
Thanks folks!
Update
根据这些问题(一、二),他们似乎仍然不确定未来的 API。他们很可能会提供一个公共 API(可能他们的意思是react-cache或更通用的东西),它本质上只是一个抛出 Promise 机制的包装器。