Skip to content

Commit

Permalink
fix: Make props optional in rerender function returned from `render…
Browse files Browse the repository at this point in the history
…HookToSnapshotStream`
  • Loading branch information
jerelmiller committed Jan 13, 2025
1 parent b209c2e commit f7b9229
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/renderHookToSnapshotStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ export interface SnapshotStream<Snapshot, Props> extends Assertable {
* Does not advance the render iterator.
*/
waitForNextSnapshot(options?: NextRenderOptions): Promise<Snapshot>
rerender: (rerenderCallbackProps: Props) => Promise<void>
rerender: (rerenderCallbackProps?: Props) => Promise<void>
unmount: () => void
}

export async function renderHookToSnapshotStream<ReturnValue, Props>(
renderCallback: (props: Props) => ReturnValue,
renderCallback: (props?: Props) => ReturnValue,
{initialProps, ...renderOptions}: RenderHookOptions<Props> = {},
): Promise<SnapshotStream<ReturnValue, Props>> {
const {render, ...stream} = createRenderStream<{value: ReturnValue}, never>()

const HookComponent: React.FC<{arg: Props}> = props => {
const HookComponent: React.FC<{arg?: Props}> = props => {
stream.replaceSnapshot({value: renderCallback(props.arg)})
return null
}

const {rerender: baseRerender, unmount} = await render(
<HookComponent arg={initialProps!} />,
<HookComponent arg={initialProps} />,
renderOptions,
)

function rerender(rerenderCallbackProps: Props) {
function rerender(rerenderCallbackProps?: Props) {
return baseRerender(<HookComponent arg={rerenderCallbackProps} />)
}

Expand Down

0 comments on commit f7b9229

Please sign in to comment.