@meterbox/react 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/react",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Embeddable React components for Meterbox: pricing tables, subscription preview, credit balance and usage charts. Presentational by default, with data fetched by your backend via @meterbox/node.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://meterbox.ai",
@@ -156,15 +156,21 @@ function PlanChangeCard({
156
156
  const [scheduled, setScheduled] = React.useState(scheduledChange || null);
157
157
  // "now" or "period_end" while the customer is asked to confirm it.
158
158
  const [asking, setAsking] = React.useState(null);
159
+ // Another plan picked while asking: ask again for that one. Reset as it
160
+ // renders, not in an effect: React runs a render's pending effects before
161
+ // it handles a click, so one that reset this on mount could undo a click on
162
+ // "Change now" that came first.
163
+ const [askedFor, setAskedFor] = React.useState(planId);
164
+ if (askedFor !== planId) {
165
+ setAskedFor(planId);
166
+ setAsking(null);
167
+ }
159
168
  const { t, date, money } = useI18n();
160
169
 
161
170
  React.useEffect(() => {
162
171
  setScheduled(scheduledChange || null);
163
172
  }, [scheduledChange]);
164
173
 
165
- // Another plan picked while asking: ask again for that one.
166
- React.useEffect(() => setAsking(null), [planId]);
167
-
168
174
  // The buttons asked about are gone, so focus moves to the safe answer.
169
175
  const keepRef = React.useRef(null);
170
176
  React.useEffect(() => {