0.20.0 • Published 4 years ago

@re-frame/react v0.20.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

@re-frame/react

  1. Make your store available via React context by using Provider from @re-frame/react at the top of your application. This will allow you to access subscriptions and dispatch events within the React tree.
import React from "react"
import ReactDOM from "react-dom"
import {createStore} from "@re-frame/standalone"
import {Provider} from "@re-frame/react"

const store = createStore()

const App = () => (
  <Provider store={store}>
    <YourAppGoesHere />
  </Provider>
)

ReactDOM.render(<App />, document.getElementById("root"))
  1. Subscribe to your store from within the tree.
import React from "react"
import {useSubscription} from "@re-frame/react"

const ChatList = () => {
  const chats = useSubscription("chats")
  return (
    <ol>
      {chats.map(chat => (
        <li key={chat.id}>{chat.title}</li>
      )}
    </ol>
  )
}
  1. Dispatch events to your store.
import React from "react"
import {useDispatch} from "@re-frame/react"

const MyComponent = () => {
  const dispatch = useDispatch()
  return (
    <button onClick={() => dispatch({id: "my-event"})}>
      Click me to trigger "my-event"
    </button>
  )
}
0.20.0

4 years ago

0.19.0

4 years ago

0.18.0

5 years ago

0.17.0

5 years ago

0.16.0

5 years ago

0.15.0

5 years ago

0.14.0

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago