Skip to content

Commit 1c49bf5

Browse files
committed
Add typescript func example
1 parent 7b84a94 commit 1c49bf5

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

examples/ts/UserPage.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
2-
import UserWidget from './UserWidget'
2+
import UserWidgetComp from './UserWidgetComp'
3+
import UserWidgetFunc from './UserWidgetFunc'
34

45
interface Props {
56
userId: string,
@@ -9,7 +10,8 @@ export default class UserPage extends React.Component<Props> {
910
render() {
1011
return (
1112
<div>
12-
<UserWidget userId={this.props.userId}/>
13+
<UserWidgetComp userId={this.props.userId}/>
14+
<UserWidgetFunc userId={this.props.userId}/>
1315
</div>
1416
)
1517
}

examples/ts/UserWidget.tsx examples/ts/UserWidgetComp.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface InnerProps extends OuterProps {
1010
userFetch: PromiseState<User>
1111
}
1212

13-
class UserWidget extends React.Component<InnerProps> {
13+
class UserWidgetComp extends React.Component<InnerProps> {
1414
render() {
1515
return (
1616
<ul>
@@ -23,4 +23,4 @@ class UserWidget extends React.Component<InnerProps> {
2323

2424
export default connect<OuterProps, InnerProps>((props) => ({
2525
userFetch: `/users/${props.userId}`
26-
}))(UserWidget)
26+
}))(UserWidgetComp)

examples/ts/UserWidgetFunc.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
import { connect, PromiseState } from '../../src'
3+
import { User } from './types'
4+
5+
interface OuterProps {
6+
userId: string
7+
}
8+
9+
interface InnerProps extends OuterProps {
10+
userFetch: PromiseState<User>
11+
}
12+
13+
function UserWidgetFunc(props: InnerProps) {
14+
return (
15+
<ul>
16+
<li>{ props.userId }</li>
17+
<li>{ props.userFetch.fulfilled && props.userFetch.value.name }</li>
18+
</ul>
19+
)
20+
}
21+
22+
export default connect<OuterProps, InnerProps>((props) => ({
23+
userFetch: `/users/${props.userId}`
24+
}))(UserWidgetFunc)

0 commit comments

Comments
 (0)