JSPM

react-scope-provider

1.0.0-1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 194
    • Score
      100M100P100Q86600F
    • License MIT

    Package Exports

    • react-scope-provider

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-scope-provider) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    react-scope-provider

    npm i react-scope-provider
    // App.js
    import React from 'react'
    import { ScopeProvider } from 'react-scope-provider'
    import View from './View'
    import scope from './scope'
    
    export default () => (
      <ScopeProvider scope={scope}>
        <View />
      </ScopeProvider>
    )
    // View.js
    import React from 'react'
    import { ScopeConsumer } from 'react-scope-provider'
    
    export default props => (
      <ScopeConsumer>
        {({
          // scope can be any value, even React components
          Box,
          Heading,
        }) => (
          <Box>
            <Heading>View</Heading>
          </Box>
        )}
      </ScopeConsumer>
    )

    A default scope can be provided to the consumer when it's used outside of a provider.

    // View.js with default scope
    import React from 'react'
    import { ScopeConsumer } from 'react-scope-provider'
    
    export default props => (
      <ScopeConsumer defaultScope={scope}>
        {({
          Box,
          Heading,
        }) => (
          <Box>
            <Heading>View</Heading>
          </Box>
        )}
      </ScopeConsumer>
    )

    HOC

    import React from 'react'
    import { withScope } from 'react-scope-provider'
    
    export default withScope(({
      scope: {
        Box,
        Heading
      }
    }) => (
      <Box>
        <Heading>Hello</Heading>
      </Box>
    ))