-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jimengio/hooks-support
simplify implementation with hooks; support useContext
- Loading branch information
Showing
6 changed files
with
832 additions
and
887 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { SFC } from "react"; | ||
import { css, cx } from "emotion"; | ||
import randomcolor from "randomcolor"; | ||
|
||
import { connectRex, useRexContext } from "rex"; | ||
import { IGlobalStore } from "models/global"; | ||
import { doIncData } from "controllers/data"; | ||
import { randomBg } from "util/color"; | ||
|
||
interface IProps { | ||
passed: string; | ||
} | ||
|
||
let HooksChild: SFC<IProps> = (props) => { | ||
let contextData = useRexContext((store: IGlobalStore) => { | ||
return { | ||
data: store.data, | ||
homeData: store.homeData, | ||
}; | ||
}); | ||
|
||
return ( | ||
<div className={styleContainer} style={randomBg()}> | ||
<div>this is page inside</div> | ||
<div>passed value: {props.passed}</div> | ||
|
||
<a onClick={doIncData}>Add data</a> | ||
<pre>{JSON.stringify(contextData, null, 2)}</pre> | ||
</div> | ||
); | ||
}; | ||
|
||
const styleContainer = css` | ||
border: 1px solid #ddd; | ||
margin: 20px; | ||
padding: 20px; | ||
`; | ||
|
||
export default HooksChild; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.