Skip to content

Commit 249c80e

Browse files
authored
Merge pull request #12 from streamich/prop-types
Prop types
2 parents c4a0b90 + 955398f commit 249c80e

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# react-universal-interface
22

3+
Easily create a component which is render-prop, Function-as-a-child and component-prop.
4+
5+
```js
6+
import {render} from 'react-univerdal-interface';
7+
8+
class MyData extends React.Component {
9+
render () {
10+
return render(this.props, this.state);
11+
}
12+
}
13+
```
14+
15+
Now you can use it:
16+
17+
```jsx
18+
<MyData render={(state) =>
19+
<MyChild {...state} />
20+
} />
21+
22+
<MyData>{(state) =>
23+
<MyChild {...state} />
24+
}</MyData>
25+
26+
<MyData comp={MyChild} />
27+
<MyData component={MyChild} />
28+
```
29+
30+
---
31+
332
[![][npm-badge]][npm-url] [![][travis-badge]][travis-url] [![React Universal Interface](https://img.shields.io/badge/React-Universal%20Interface-green.svg)](https://github.com/streamich/react-universal-interface)
433

534
Use this badge if you support universal interface:
@@ -111,6 +140,24 @@ Returns a component enhancer `enhancer(Comp, propName, faccProps)` that receives
111140
- `faccProps` &mdash; optional, props to provide to the FaCC component.
112141

113142

143+
## TypeScript
144+
145+
TypeScript users can add typings to their render-prop components.
146+
147+
```ts
148+
import {UniversalProps} from 'react-universal-interface';
149+
150+
interface Props extends UniversalProps<State> {
151+
}
152+
153+
interface State {
154+
}
155+
156+
class MyData extends React.Component<Props, State> {
157+
}
158+
```
159+
160+
114161
## License
115162

116163
[Unlicense](./LICENSE) &mdash; public domain.

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import render from './render';
22
import createEnhancer from './createEnhancer';
33

4+
export interface UniversalProps<Data> {
5+
children?: ((data: Data) => React.ReactNode) | React.ReactNode;
6+
render?: (data: Data) => React.ReactNode;
7+
comp?: React.ComponentType<Data & any>;
8+
component?: React.ComponentType<Data & any>;
9+
}
10+
411
export {
512
render,
613
createEnhancer,

0 commit comments

Comments
 (0)