Skip to content

Instantly share code, notes, and snippets.

@developit
Last active June 5, 2018 14:21
Show Gist options
  • Save developit/5d879edb820228224dc9 to your computer and use it in GitHub Desktop.
Save developit/5d879edb820228224dc9 to your computer and use it in GitHub Desktop.
// - yes, this is the entire implementation
// - no, it doesn't actually depend on preact
export class Provider {
getChildContext () {
let { children, ...context } = this.props;
return context;
}
render ({ children }) {
return children && children[0] || null
}
}
@KrofDrakula
Copy link

KrofDrakula commented Feb 21, 2017

Instead of mutation, you could use destructuring to filter out any values you don't want without having to mutate:

export class Provider {
  getChildContext () {
    const { children, ...context } = this.props;
    return context;
  }
  render ({ children }) {
    return children && children[0] || null
  }
}

@developit
Copy link
Author

Amended!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment