3.0.0 • Published 1 year ago

smart-context v3.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

npm version Build Status Coverage Status semantic-release

Highlights

  • Lightweight
  • Zero setup. No boilerplate
  • 100% config driven
  • Async actions
  • Extend with plugins
  • Multiple stores/contexts
  • Easy Debugging
  • Typescript support

Installation

npm

npm install smart-context

yarn

yarn add smart-context

Quick start in 3 steps

Create store

You can create multiple stores. All stores must have a unique name.

// store.js

// Create initial state
const initialState = { name: '' }

// Create actions
const actionsConfig = {
  setName: ['name'],
}

// Provide a good name
const displayName = 'myContext'

// Setup is done! Export config
export default {
  initialState,
  actionsConfig,
  displayName,
}

Plugin smart-context

// Wrap root component in smart-context HOC
import React from 'react'
import { WithContextProvider } from 'smart-context'

import Config from './store'

const App = ({ children }) => <div id="app-container">{children}</div>

export default WithContextProvider(App, [Config])

Access store

// myAwesomeComponent.jsx

import React from 'react'
import { useSmartContext } from 'smart-context'

const MyAwesomeComponent = () => {
  const {
    state: { name },
    actions: { setName, reset },
  } = useSmartContext('myContext')

  const clickHandler = () => {
    setName({ name: 'smart-context' })
  }

  const resetHandler = () => {
    reset()
  }

  return (
    <>
      <button onClick={clickHandler}>Say Hi</button>
      <button onClick={resetHandler}>Reset</button>
      {name ? <h1>Hi, {name}</h1> : null}
    </>
  )
}

export default MyAwesomeComponent

Documentation

Visit website for full documentation and demo.

Contributing

Refer Contributing Guide.

License

MIT licensed.

3.0.0

1 year ago

2.2.1

1 year ago

2.2.0

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.0.2

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago