0.0.18 • Published 3 years ago

@bendcircular/conditional-components-react v0.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

conditional-components-react

Helper methods and components to render elements based on configurable conditions

NPM JavaScript Style Guide

Install

npm install --save @bendcircular/conditional-components-react
# or
yarn add @bendcircular/conditional-components-react

Usage

import * as React from 'react'
import {
  DEFAULT_LOCAL_STORAGE_KEY,
  ConditionalComponent,
  useLocalStorageConfig,
  useLocalStorageCondition
} from 'conditional-components-react'

const FEATURE = 'myFeature'

const App = () => {
  const { conditions, setConfig } = useLocalStorageConfig({
    storageKey: DEFAULT_LOCAL_STORAGE_KEY
  })
  const isActive = useLocalStorageCondition({
    condition: FEATURE,
    additionals: {}
  })

  const toggleActivation = React.useCallback(() => {
    setConfig({ ...conditions, [FEATURE]: !isActive })
  }, [conditions, isActive, setConfig])

  return (
    <div>
      <div>App</div>
      <button onClick={toggleActivation}>
        {isActive ? 'deactivate' : 'activate'}
      </button>
      <ConditionalComponent condition={FEATURE} config={{ myFeature: false }}>
        <div>This is my conditional component</div>
      </ConditionalComponent>
    </div>
  )
}

export default App

License

MIT © bendcircular GmbH

0.0.17

3 years ago

0.0.18

3 years ago

0.0.16

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago