|
| 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 | + |
1 | 81 | ## 0.8.10 (2019-10-10)
|
2 | 82 | [Compare `@uirouter/react` versions 0.8.9 and 0.8.10](https://github.com/ui-router/react/compare/0.8.9...0.8.10)
|
3 | 83 |
|
|
0 commit comments