I'm trying to create a payment screen in React using Recurly.js. I'm using the official React library and am trying to hook into the set.plan
event to retrieve plan information. I previously did this without issue using vanilla Recurly.js in Angular, but I haven't been able to do so in React and it's not clear to me if I'm doing something wrong or if there's a bug.
I adapted one of the Interactive Demo scenarios to demonstrate this. Please see the comments added in my sandbox:
const [{ price, loading }, setPricing, checkoutPricing] = useCheckoutPricing(
null,
setRecurlyError
);
useEffect(() => {
/*
Should this be called frequently? I know the price state gets updated, but I would not
expect to constantly receive a new/updated instance of checkoutPricing.
*/
console.log("checkoutPricing updated", checkoutPricing);
/*
This never gets called even after selecting a new plan in the dropdown menu
*/
checkoutPricing.on("set.plan", (plan) => {
console.log("plan updated", plan);
});
}, [checkoutPricing]);
Am I getting a new instance of checkoutPricing on each render? That might explain why my event is never firing, but I'm not sure how to avoid that.