Skip to content

Commit

Permalink
docs: add contextType example
Browse files Browse the repository at this point in the history
  • Loading branch information
jepser committed Apr 4, 2020
1 parent 3a6bd78 commit 4a85c2a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ const Room = ({ roomId }) => {
}
```
### Using the library with class components
For the cases that you need to use the library with class components, import the context and use it as a common [provider/consumer](https://reactjs.org/docs/context.html#reactcreatecontext) component:
``` jsx
import { TrackingContext } from 'treacker'

class MyClass extends React.Component {
componentDidMount() {
const tracking = this.context;

tracking.track('user-component.loaded')
}
}
MyClass.contextType = TrackingContext;
```
### HOC
WIP: `withTracking()`
Expand Down

0 comments on commit 4a85c2a

Please sign in to comment.