Create a new react hook called prestate

This issue has been tracked since 2022-09-16.

I want to add a new react hook called prestate hook this hook will allow accessing previous values that the user assigned
I'm going to work on it if someone is interested in it then please leave a comment

DIWAKARKASHYAP wrote this answer on 2022-09-17

i am interested to work on it but i have no experience in opensource

amirqasemi74 wrote this answer on 2022-09-19

what do you mean by pre-state. when you are going to set state, as you know setState accepts a function as value which react pass pre value of state as argument to it and it returns new state. there you have pre-state. if you need more, please explain more with the api you mean

matvp91 wrote this answer on 2022-09-19

Wouldn't this work, assuming I'm not missing the point.

function usePrevState(value) {
  const ref = useRef();
  useEffect(() => {
    ref.current = value;
  }, [value]);
  return ref.current;
}

const [value, setValue] = useState(1);
const prevValue = usePrevState(value);
varwasabi wrote this answer on 2022-09-21

usePrevious is a well known custom hook and I assume it is what you're asking for. I'm not sure there's a place for it in core though as it has a specific use case and not something that would be used in every application unlike those already part of react core.

madhusudhan123-star wrote this answer on 2022-09-27

Even I am also interested but have zero experience in open-source. varwasabi commented use previous and also alternative options.

umerprogramm wrote this answer on 2022-09-27
-1

Hello Everyone!
Thanks for making your interest in it. So a lot of guys are interested, But they not understanding what I'm actually trying to say.
prestate Hook is just not going to be Hook that contains the previous values but it also contains some cool methods Like:

  • Binary Search
  • sorting Arrays
  • Reduce the repeated elements from the array
    And much more. (If you have an idea feel free to leave a comment I will definitely put that on my list)

I will soon put a code example that helps to visualize what I'm trying to say.

More Details About Repo
Owner Name facebook
Repo Name react
Full Name facebook/react
Language JavaScript
Created Date 2013-05-24
Updated Date 2022-10-03
Star Count 195560
Watcher Count 6648
Fork Count 40508
Issue Count 1111

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date