0.2.10 • Published 1 month ago

somestate-react v0.2.10

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

Somestate React

Install

npm install somestate-react

Documentation

More docs available at https://github.com/Kottakji/somestate

Hooks

useStore

import { useStore } from 'somestate/react'
import { store } from 'somestate'

// Or import it from src/stores/countStore.js
const $count = store(0);

export const Example = () => {
  const count = useStore($count)

  return (
    <div>
        <p>Total: {count}</p>
        <button onClick={() => $count.set($count.get() + 1)}/>
    </div>
  )
}

useFetched

This includes the data, loading and error values that can be destructured.

import { useStore } from 'somestate/react'
import { fetched } from 'somestate'

// Or import it from src/stores/countStore.js
const $todos = fetched(`https://jsonplaceholder.typicode.com/todos`)

export const Todos = () => {
  const {data: todos, loading, error} = useFetched($todos)

  if (loading) {
    return <></>
  }

  return (
    <ul>
        {todos.map(todo => <li>{todo.id}</li>)}
    </ul>
  )
}
0.2.10

1 month ago

0.2.9

5 months ago

0.2.8

5 months ago

0.2.7

5 months ago

0.2.6

5 months ago

0.2.5

5 months ago

0.2.4

5 months ago

0.2.3

5 months ago

0.2.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.0

6 months ago