Skip to content

Commit 8b4eb74

Browse files
authored
react.forwardRef support (requires react >=16.8.3) (#6)
1 parent cc097d7 commit 8b4eb74

8 files changed

Lines changed: 1255 additions & 908 deletions

File tree

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented here. The format is based
44
on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project
55
adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
9+
### Added
10+
11+
- *Breaking*: `ref` support, thanks to [`React.forwardRef`](https://reactjs.org/docs/forwarding-refs.html)
12+
713
## 2019/03/28 0.6.1
814

915
### Changed

README.md

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,30 @@ React components dynamically based on the requested client-package.
1212

1313
## Getting started
1414

15-
```bash
15+
```sh
1616
npm i react-component-catalog --save
17+
18+
# or
19+
yarn add react-component-catalog
1720
```
1821

19-
## Basic Usage
22+
Then install the correct versions of each peerDependency package, which are
23+
listed by the command:
24+
25+
```sh
26+
npm info "react-component-catalog@latest" peerDependencies
27+
```
28+
29+
If using npm 5+, use this shortcut:
30+
31+
```sh
32+
npx install-peerdeps --dev react-component-catalog
2033

21-
### Requirements
34+
# or
35+
yarn add react-component-catalog -D --peer
36+
```
2237

23-
As this package depends on [`react-hooks`](https://reactjs.org/docs/hooks-overview.html),
24-
`"react": "^16.8.0"` and `"react-dom": "^16.8.0"` are required (see
25-
`peerDependencies` in [package.json](./package.json)).
38+
## Basic Usage
2639

2740
### First register the components
2841

@@ -134,6 +147,39 @@ const App = () => {
134147
export default App
135148
```
136149

150+
### Use catalog with `ref`
151+
152+
> Refs provide a way to access DOM nodes or React elements created in the render
153+
method. ([Source: reactjs.org](https://reactjs.org/docs/refs-and-the-dom.html))
154+
155+
It is possible to use `react-component-catalog` with `ref` as well. It would
156+
look similar to (works also with `<CatalogComponent />`):
157+
158+
```js
159+
const TestComponent = withCatalog(props => (
160+
<button {...props} type="button">
161+
Hello Button
162+
</button>
163+
))
164+
165+
/* eslint-disable react/no-multi-comp */
166+
class App extends React.Component {
167+
constructor(props) {
168+
super(props)
169+
this.setRef = React.createRef()
170+
}
171+
172+
render() {
173+
// or <CatalogComponent component="TestComponent" ref={this.setRef} />
174+
return (
175+
<CatalogProvider catalog={new Catalog({ components: { TestComponent } })}>
176+
<TestComponent ref={this.setRef} />
177+
</CatalogProvider>
178+
)
179+
}
180+
}
181+
```
182+
137183
## How to build and test this package
138184

139185
```sh

jest.setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
12
import { configure } from 'enzyme'
23
import Adapter from 'enzyme-adapter-react-16'
34

0 commit comments

Comments
 (0)