项目作者: leops

项目描述 :
Renderer-Agnostic portals for React
高级语言: TypeScript
项目地址: git://github.com/leops/react-jumpgate.git
创建时间: 2018-10-09T19:22:20Z
项目社区:https://github.com/leops/react-jumpgate

开源协议:

下载


react-jumpgate

A generic implementation of portals for React, for platforms where ReactDOM is not available
(eg. this could be used in a React Native application to add buttons to the toolbar from any component in the tree)

  1. import createJumpgate from 'react-jumpgate';
  2. // A jumpgate is made of 3 components: an anchor, a consumer and a provider
  3. const { Anchor, Consumer, Provider } = createJumpgate();
  4. const App = () => (
  5. <div class="app">
  6. {/* Place the anchor near the root of your component tree */}
  7. <Anchor>
  8. <div class="header">
  9. {/* The consumer acts as a placeholder for the component you want to teleport */}
  10. <Consumer ></Consumer>
  11. </div>
  12. <div class="content">
  13. {/* The provider will send its children through the jumpgate to the consumer */}
  14. <Provider>
  15. <h1>Title</h1>
  16. </Provider>
  17. </div>
  18. </Anchor>
  19. </div>
  20. );
  21. /* <App ></App> will render as
  22. <div class="app">
  23. <div class="header">
  24. <h1>Title</h1>
  25. </div>
  26. <div class="content" ></div>
  27. </div>
  28. */