Skip to content

Instantly share code, notes, and snippets.

@bluepnume
Last active March 6, 2020 02:06
Show Gist options
  • Save bluepnume/51e6f2e386f64563dfc7b4a3b3f8f418 to your computer and use it in GitHub Desktop.
Save bluepnume/51e6f2e386f64563dfc7b4a3b3f8f418 to your computer and use it in GitHub Desktop.
const useSetup = (setup, plan) => {
const ref = useRef(plan);
useEffect(() => {
ref.current = plan;
}, [ plan ]);
useEffect(() => {
const data = {};
const actions = {
submit: () => {
alert('paying with plan: ' + ref.current)
}
};
setup(data, actions)
}, []);
}
function App() {
const [ plan, setPlan ] = useState('default plan');
useSetup(setup, plan);
return (
<input
value={plan}
onChange={ event => setPlan(event.target.value) }
/>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment