MultiProvider.js 669 B

1234567891011121314151617181920212223242526272829
  1. import React from "react";
  2. export const MultiProvider = (props) => {
  3. let content = props.children || null;
  4. /* Error/Validation */
  5. if (!props.providers) {
  6. throw "MultiProvider: Missing providers prop";
  7. }
  8. if (!props.children) {
  9. throw "MultiProvider: Missing children";
  10. }
  11. // Turn object into an array
  12. // const numberOfProviders = props.providers.size;
  13. const numberOfProviders = props.providers.length;
  14. if (!numberOfProviders) {
  15. // Providers prop is empty, r
  16. return content;
  17. }
  18. [...(props.providers ?? [])].reverse().forEach((provider) => {
  19. content = React.cloneElement(provider, null, content);
  20. });
  21. return content;
  22. };