react-native-mapsforge-vtm
Version:
React Native components to build vector maps using Mapsforges fork of vtm. Offline rendering of OpenStreetMap data. Android only
25 lines (22 loc) • 574 B
text/typescript
/**
* External dependencies
*/
import { useRef } from 'react';
/**
* Like useState, returns a stateful value, and a function to update it.
* But uses a ref instead of a state.
* Like this react manages to "update the state" of many sibling components concurrently. Well, it's not updating the state actually, it's updating the ref.
*/
const useRefState = ( initial: any ) : [
any,
( newVal: any )=> void,
] => {
const stateRef = useRef( initial );
return [
stateRef?.current,
newVal => {
stateRef.current = newVal;
},
];
};
export default useRefState;