MCPcopy
hub / github.com/pmndrs/react-spring / createUpdater

Function createUpdater

packages/core/src/hooks/useSpring.test.tsx:421–460  ·  view source on GitHub ↗
(Component: React.ComponentType<{ args: [any, any?] }>)

Source from the content-addressed store, hash-verified

419}
420
421function createUpdater(Component: React.ComponentType<{ args: [any, any?] }>) {
422 let prevElem: React.JSX.Element | undefined
423 let result: Awaited<ReturnType<typeof render>> | undefined
424
425 const context: TestContext = {
426 async set(values) {
427 Object.assign(this, values)
428 if (prevElem) {
429 await renderWithContext(prevElem)
430 }
431 },
432 }
433 // Ensure `context.set` is ignored.
434 Object.defineProperty(context, 'set', {
435 value: context.set,
436 enumerable: false,
437 })
438
439 afterEach(() => {
440 result = prevElem = undefined
441 for (const key in context) {
442 delete (context as any)[key]
443 }
444 })
445
446 async function renderWithContext(elem: React.JSX.Element) {
447 const wrapped = (
448 <SpringContextProvider {...context}>{elem}</SpringContextProvider>
449 )
450 if (result) await result.rerender(wrapped)
451 else result = await render(wrapped)
452 return result
453 }
454
455 type Args = Parameters<typeof useSpring>
456 const update = (...args: [Args[0], Args[1]?]) =>
457 renderWithContext((prevElem = <Component args={args} />))
458
459 return [update, context] as const
460}
461
462function testIsRef(ref: SpringRef | null) {
463 const props = [

Callers 1

useSpring.test.tsxFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…