react-transition-state 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,7 +22,7 @@ Inspired by the [React Transition Group](https://github.com/reactjs/react-transi
22
22
 
23
23
  ## State diagram
24
24
 
25
- ![state-diagram](https://user-images.githubusercontent.com/41896553/142855447-cb8d8730-f8fb-4296-a3db-d1523b0fa2d9.png) The `initialEntered` and `mountOnEnter` props are omitted from the diagram to keep it less convoluted. [Please read more details at the API section](#usetransition-hook).
25
+ ![state-diagram](https://user-images.githubusercontent.com/41896553/142855447-cb8d8730-f8fb-4296-a3db-d1523b0fa2d9.png) The `initialEntered` and `mountOnEnter` props are omitted from the diagram to keep it less convoluted. [Please read more details at the API section](#usetransitionstate-hook).
26
26
 
27
27
  <br/>
28
28
 
@@ -43,11 +43,10 @@ yarn add react-transition-state
43
43
  ### CSS example
44
44
 
45
45
  ```jsx
46
- import { useTransition } from 'react-transition-state';
47
- /* or import useTransition from 'react-transition-state'; */
46
+ import { useTransitionState } from 'react-transition-state';
48
47
 
49
48
  function Example() {
50
- const [state, toggle] = useTransition({ timeout: 750, preEnter: true });
49
+ const [state, toggle] = useTransitionState({ timeout: 750, preEnter: true });
51
50
  return (
52
51
  <div>
53
52
  <button onClick={() => toggle()}>toggle</button>
@@ -83,7 +82,7 @@ export default Example;
83
82
 
84
83
  ```jsx
85
84
  import styled from 'styled-components';
86
- import { useTransition } from 'react-transition-state';
85
+ import { useTransitionState } from 'react-transition-state';
87
86
 
88
87
  const Box = styled.div`
89
88
  transition: all 500ms;
@@ -97,7 +96,7 @@ const Box = styled.div`
97
96
  `;
98
97
 
99
98
  function StyledExample() {
100
- const [{ status, isMounted }, toggle] = useTransition({
99
+ const [{ status, isMounted }, toggle] = useTransitionState({
101
100
  timeout: 500,
102
101
  mountOnEnter: true,
103
102
  unmountOnExit: true,
@@ -134,7 +133,7 @@ export default StyledExample;
134
133
 
135
134
  You can create switch transition effects using one of the provided hooks,
136
135
 
137
- - `useTransition` if the number of elements participating in the switch transition is static.
136
+ - `useTransitionState` if the number of elements participating in the switch transition is static.
138
137
  - `useTransitionMap` if the number of elements participating in the switch transition is dynamic and only known at runtime.
139
138
 
140
139
  **[Edit on CodeSandbox](https://codesandbox.io/p/sandbox/react-switch-transition-x87jt8)**
@@ -173,10 +172,10 @@ This [CodeSandbox example](https://codesandbox.io/s/react-transition-state-vs-gr
173
172
 
174
173
  ## API
175
174
 
176
- ### `useTransition` Hook
175
+ ### `useTransitionState` Hook
177
176
 
178
177
  ```typescript
179
- function useTransition(
178
+ function useTransitionState(
180
179
  options?: TransitionOptions
181
180
  ): [TransitionState, (toEnter?: boolean) => void, () => void];
182
181
  ```
@@ -197,7 +196,7 @@ function useTransition(
197
196
 
198
197
  #### Return value
199
198
 
200
- The `useTransition` Hook returns a tuple of values in the following order:
199
+ The `useTransitionState` Hook returns a tuple of values in the following order:
201
200
 
202
201
  1. state:
203
202
 
@@ -231,11 +230,11 @@ The `useTransition` Hook returns a tuple of values in the following order:
231
230
 
232
231
  ### `useTransitionMap` Hook
233
232
 
234
- It's similar to the `useTransition` Hook except that it manages multiple states in a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) structure instead of a single state.
233
+ It's similar to the `useTransitionState` Hook except that it manages multiple states in a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) structure instead of a single state.
235
234
 
236
235
  #### Options
237
236
 
238
- It accepts all options as `useTransition` and the following ones:
237
+ It accepts all options as `useTransitionState` and the following ones:
239
238
 
240
239
  | Name | Type | Default | Description |
241
240
  | --- | --- | --- | --- |
package/dist/cjs/index.js CHANGED
@@ -45,7 +45,7 @@ const updateState$1 = (status, setState, latestState, timeoutId, onChange) => {
45
45
  current: state
46
46
  });
47
47
  };
48
- const useTransition = ({
48
+ const useTransitionState = ({
49
49
  enter = true,
50
50
  exit = true,
51
51
  preEnter,
@@ -199,6 +199,7 @@ const useTransitionMap = ({
199
199
  };
200
200
  };
201
201
 
202
- exports.default = useTransition;
203
- exports.useTransition = useTransition;
202
+ exports.default = useTransitionState;
203
+ exports.useTransition = useTransitionState;
204
204
  exports.useTransitionMap = useTransitionMap;
205
+ exports.useTransitionState = useTransitionState;
@@ -10,7 +10,7 @@ const updateState = (status, setState, latestState, timeoutId, onChange) => {
10
10
  current: state
11
11
  });
12
12
  };
13
- const useTransition = ({
13
+ const useTransitionState = ({
14
14
  enter = true,
15
15
  exit = true,
16
16
  preEnter,
@@ -57,4 +57,4 @@ const useTransition = ({
57
57
  return [state, toggle, endTransition];
58
58
  };
59
59
 
60
- export { useTransition };
60
+ export { useTransitionState };
package/dist/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { useTransition as default, useTransition } from './hooks/useTransition.js';
1
+ export { useTransitionState as default, useTransitionState as useTransition, useTransitionState } from './hooks/useTransitionState.js';
2
2
  export { useTransitionMap } from './hooks/useTransitionMap.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-transition-state",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "description": "Zero dependency React transition state machine.",
5
5
  "author": "Zheng Song",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "@eslint/compat": "^1.1.1",
46
46
  "@rollup/plugin-babel": "^6.0.4",
47
47
  "@testing-library/react": "^16.0.1",
48
- "@types/jest": "^29.5.13",
48
+ "@types/jest": "^29.5.14",
49
49
  "babel-plugin-pure-annotations": "^0.1.2",
50
50
  "eslint": "^9.9.1",
51
51
  "eslint-config-prettier": "^9.1.0",
@@ -53,7 +53,7 @@
53
53
  "eslint-plugin-react": "^7.37.1",
54
54
  "eslint-plugin-react-hooks": "^4.6.2",
55
55
  "eslint-plugin-react-hooks-addons": "^0.3.1",
56
- "globals": "^15.10.0",
56
+ "globals": "^15.11.0",
57
57
  "jest": "^29.7.0",
58
58
  "jest-environment-jsdom": "^29.7.0",
59
59
  "npm-run-all": "^4.1.5",
@@ -61,7 +61,7 @@
61
61
  "react": "^18.3.1",
62
62
  "react-dom": "^18.3.1",
63
63
  "rollup": "^4.24.0",
64
- "typescript": "^5.6.2"
64
+ "typescript": "^5.6.3"
65
65
  },
66
66
  "overrides": {
67
67
  "eslint-plugin-react-hooks": {
package/types/index.d.ts CHANGED
@@ -46,8 +46,18 @@ export interface TransitionMapResult<K> {
46
46
  deleteItem: (key: K) => boolean;
47
47
  }
48
48
 
49
- export const useTransition: (options?: TransitionOptions) => TransitionResult;
49
+ export const useTransitionState: (options?: TransitionOptions) => TransitionResult;
50
50
 
51
51
  export const useTransitionMap: <K>(options?: TransitionMapOptions<K>) => TransitionMapResult<K>;
52
52
 
53
- export default useTransition;
53
+ export {
54
+ /**
55
+ * @deprecated The `useTransition` alias will be removed in v3.0.0. Use `useTransitionState` instead.
56
+ */
57
+ useTransitionState as useTransition
58
+ };
59
+
60
+ /**
61
+ * @deprecated The default export will be removed in v3.0.0. Use the named export `useTransitionState` instead.
62
+ */
63
+ export default useTransitionState;