This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export default function useSpecialEffect( | |
callback: (prevRef: any) => any, | |
updatables: any = {} // Passing false here means the effect will only run once. Like passing [] to useEffect() | |
): void { | |
const prevRef = React.useRef<any>({}); | |
const renderCountRef = React.useRef<number>(0); | |
prevRef.current.update = (propertyString: string, value: any) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [someValue1, setSomeValue1] = useState(null); | |
const [someValue2, setSomeValue2] = useState(false); | |
const anotherValueThatCanChange = "some other value"; | |
const [someValue0, setSomeValue0] = useState(true); // Some state that we don't necessarily want to track changes | |
// This hook will run on every render... similar to useEffect(()=>{}) | |
useSpecialEffect((prev) => { | |
if (prev.hasChanged({someValue1}, {anotherValueThatCanChange})) { | |
// Do stuff if someValue1 or anotherValueThatCanChange is updated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code has been moved to: https://github.com/rafaelgandi/WidgetMarkup-Scriptable | |