Skip to content

Commit ef2a0f0

Browse files
committed
Limit what we are exposing from internal state
1 parent 9d0d275 commit ef2a0f0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/mdx/src/mdx-client/slideshow.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,21 @@ export function Slideshow({
5151
stepIndex: initialSlide,
5252
step: editorSteps[initialSlide],
5353
})
54-
const tab = state.step
54+
55+
// Destructure these values and give them more semantic names for use below
56+
const {
57+
stepIndex: currentSlideIndex,
58+
step: tab,
59+
} = state;
5560

5661
// Run any time our Slideshow state changes
5762
React.useEffect(() => {
5863
// Return our state object to the Slideshow onChange function
59-
onSlideshowChange(state);
60-
}, [state]);
64+
onSlideshowChange({
65+
index: currentSlideIndex
66+
});
67+
// We are only calling this effect if the current slide changes.
68+
}, [currentSlideIndex]);
6169

6270
function onTabClick(filename: string) {
6371
const newStep = updateEditorStep(
@@ -95,7 +103,7 @@ export function Slideshow({
95103
) : hasPreviewSteps ? (
96104
<Preview
97105
className="ch-slideshow-preview"
98-
{...previewChildren[state.stepIndex]["props"]}
106+
{...previewChildren[currentSlideIndex]["props"]}
99107
/>
100108
) : null}
101109
</div>
@@ -151,7 +159,7 @@ export function Slideshow({
151159

152160
{hasNotes && (
153161
<div className="ch-slideshow-note">
154-
{stepsChildren[state.stepIndex]}
162+
{stepsChildren[currentSlideIndex]}
155163
</div>
156164
)}
157165
</div>

0 commit comments

Comments
 (0)