Andarist / Andarist/use-previous
Deprecate?
- Dominant language
- JavaScript
- Stars
- 6
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
I guess `use-previous` should be deprecated in the longer term based on the current React docs, but it could be replaced with this implementation for the time being to be React Compiler-compatible:
```tsx
import { useState } from 'react';
/**
* @deprecated See alternatives from https://react.dev/reference/react/useState#storing-information-from-previous-renders
*/
export default function usePrevious(value: Value) {
const [prevTrackedVal, setPrevTrackedVal] = useState();
const [prevVal, setPrevVal] = useState();
if (value !== prevTrackedVal) {
setPrevTrackedVal(value);
setPrevVal(prevTrackedVal);
}
return prevVal;
}
```
It has different performance characteristics than the previous implementation though.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.