react-effin
v1.0.6
Published
different version of some react hooks that pass the dependency array into the functions that are called, i think this makes it easier to make re-usable code and make it easier to avoid forgetting adding the dependancies
Downloads
10
Readme
Getting Started with use effin
Basics
This library is for slightly more functional versions of some items from react. basically they pass the arguments from the dependency list into the function calls. this lets you define functions for these outside of the context and avoid re-creating on each render.
useFnMemo
the signiture for this is the most similar to the React.useMemo
//was
const memo = useMemo(() => value * 5, [value])
//in this now...
//outside of the component even, or shared library
const memoFn = (value) => value * 5;
//in the component
const fnMemo = useFnMemo(memoFn, [value])
useFnEffect
This signiture is compatible overall with the normal useEffect
//was
useEffect(() => {
fetch(url).then(setValue)
}, [url, setValue])
//in this now...
//outside of the component even, or shared library
const fetchFn = (url, setValue) => {
fetch(url).then(setValue)
return (url, setValue) => {
//cleanup functionality works, but also gets values passed in.
}
};
//in the component
useFnEffect(fetchFn, [value, setValue])
All variables are passed into the function in the order they are put into the array(s)
Things in process/ need some work
- [ ] expansion needed? (useFnCallback seems like it would just be a useMemo)