Skip to content

Commit f50e812

Browse files
1.0.0
1 parent 4f04a8e commit f50e812

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

CHANGELOG.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,83 @@
1+
# 1.0.0 (2020-01-07)
2+
[Compare `@uirouter/react` versions 0.8.10 and 1.0.0](https://github.com/ui-router/react/compare/0.8.10...1.0.0)
3+
4+
This is a long overdue release of UI-Router for React version 1.0.
5+
This release adds a react hooks API.
6+
7+
### Bug Fixes
8+
9+
* **errors:** Always throw a new Error() so stacktraces are usable ([26f6989](https://github.com/ui-router/react/commit/26f6989))
10+
* **typescript:** Type onClick as MouseEventHandler<any>. ([7512f14](https://github.com/ui-router/react/commit/7512f14))
11+
* **UISrefActive:** Avoid reusing the same array reference during setState() call ([b9064cd](https://github.com/ui-router/react/commit/b9064cd))
12+
13+
14+
## Features
15+
16+
Add hooks:
17+
18+
### `useRouter`
19+
20+
```js
21+
function GoHome() {
22+
const { stateService } = useRouter();
23+
return <button onClick={() => stateService.go('home')}>Home</a>
24+
}
25+
```
26+
27+
### `useSref`
28+
29+
```js
30+
function LinkHome() {
31+
const sref = useSref('home')
32+
return <a {...sref}>Home</a>
33+
}
34+
```
35+
`<a href="/home" onClick=...>Home</a>`
36+
37+
### `useSrefActive` and `uiSrefActiveExact`
38+
```js
39+
function LinkHome() {
40+
const sref = useSrefActive('home', {}, 'active')
41+
return <a {...sref}>Home</a>
42+
}
43+
```
44+
`<a href="/home" onClick=... className="active">Home</a>`
45+
46+
### `useTransitionHook`
47+
```js
48+
function CanExit() {
49+
const isDirty = useIsFormDirty();
50+
useTransitionHook("onBefore", { exiting: 'forms' }, () => isDirty ? false : true)
51+
}
52+
```
53+
54+
### `useCurrentStateAndParams`
55+
```js
56+
function CurrentState() {
57+
const { state, params } = useCurrentStateAndParams();
58+
return <div>{state.name} {JSON.stringify(params)}</div>
59+
}
60+
```
61+
62+
### `useOnStateChanged`
63+
This is a callback style hook that `useCurrentStateAndParams` and `isActive` is built on top of, used to avoid excessive renders in `isActive`
64+
```js
65+
function CurrentState() {
66+
const [stateName, setStateName] = useState();
67+
useOnStateChanged((state, params) => setStateName(state.name));
68+
return <div>{stateName}</div>
69+
}
70+
```
71+
72+
### `useIsActive`
73+
```js
74+
function CurrentState() {
75+
const isHomeActive = useIsActive('home');
76+
return <div>{isHomeActive ? 'You are home!' : 'try to find your way back'}</div>
77+
}
78+
```
79+
80+
181
## 0.8.10 (2019-10-10)
282
[Compare `@uirouter/react` versions 0.8.9 and 0.8.10](https://github.com/ui-router/react/compare/0.8.9...0.8.10)
383

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uirouter/react",
3-
"version": "0.8.10",
3+
"version": "1.0.0",
44
"description": "State based routing for React",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
@@ -82,10 +82,19 @@
8282
"webpack-dev-server": "^3.9.0"
8383
},
8484
"jest": {
85-
"setupFiles": [ "../jest.setup.js" ],
85+
"setupFiles": [
86+
"../jest.setup.js"
87+
],
8688
"rootDir": "src",
87-
"transform": { ".(ts|tsx)": "ts-jest" },
88-
"moduleFileExtensions": [ "js", "json", "ts", "tsx" ],
89+
"transform": {
90+
".(ts|tsx)": "ts-jest"
91+
},
92+
"moduleFileExtensions": [
93+
"js",
94+
"json",
95+
"ts",
96+
"tsx"
97+
],
8998
"globals": {
9099
"ts-jest": {
91100
"tsConfig": "./tsconfig.jest.json"

0 commit comments

Comments
 (0)