Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from "react";
- const propsAvailable = {
- http: 'http',
- config: 'config',
- };
- /**
- * Injects the requested props from available props
- *
- * @param props
- * @returns {function(*=): {new(): Proxy, prototype: Proxy}}
- */
- export function injectProps(props = []) {
- // get the props requested
- const injects = {};
- for (const prop in props) {
- if (propsAvailable[props[prop]] !== undefined) {
- injects[props[prop]] = propsAvailable[props[prop]];
- }
- }
- // return the component through a function wrapper
- return function (Component) {
- return class Proxy extends React.Component {
- render() {
- return React.createElement(Component, {
- ...injects,
- ...this.props,
- });
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement