react
react copied to clipboard
Create a new react hook called prestate
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
i am interested to work on it but i have no experience in opensource
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
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);
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.
Even I am also interested but have zero experience in open-source. varwasabi commented use previous and also alternative options.
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.
@umerprogramm if you need some things like that, maybe you can write it. But I think this place is not the correct to report that. Thanks mate! 👍
Hello Everyone I created the hum state Hook repo It is a great opportunity to contribute to open source
link : Humstate