1.6.11 • Published 5 years ago

@dot-event/react v1.6.11

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@dot-event/react

React integration for dot-event.

@dot-event/react

Install

npm install --save @dot-event/store @dot-event/react

What it does

This integration provides a React context provider and consumer that passes the dot-event instance down to any component.

Higher order components

We add the provider and the consumer to your component chain via higher order component "composers". Most of the examples below walk you through using the composers.

Re-render on emit

Additionally, any dot-event emit triggers a forceRender() from the provider, leaving it to your child components' shouldComponentUpdate() function to decide whether they should render.

Provider composer

Create a provider composer (withEventsProvider.js):

import dotEvent from "dot-event"
import dotStore from "@dot-event/store"
import { withEventsProvider } from "@dot-event/react"

export default withEventsProvider(dotStore)

Add the consumer

Add the consumer and pass it to the provider composer:

import React from "react"
import { withEvents } from "@dot-event/react"
import withEventsProvider from "./withEventsProvider"

class Component extends React.Component {
  static async getInitialProps({ events }) {
    await events.set("message", "hello world")
  }
  render() {
    const { events } = this.props
    return events.get("message")
  }
}

export default withEventsProvider(withEvents(Component))

Read more about React context if you're not sure how the provider/consumer relationship works.

1.6.11

5 years ago

1.6.8

5 years ago

1.6.7

5 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.3.0

5 years ago