diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c3f4fe..972e236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 2.0.1 + +- [#104](https://github.com/bvaughn/react-virtualized-auto-sizer/pull/104): Separate `renderProp` and `ChildComponent` props. + # 2.0.0 Version 2 simplifies the API and improves TypeScript support. diff --git a/README.md b/README.md index d0abeae..7a7c378 100644 --- a/README.md +++ b/README.md @@ -24,24 +24,7 @@ Measures the available width and height of its parent `HTMLElement` and passes t #### Required props - - - - - - - - - - - - - - -
NameDescription
Child

Child component to be passed the available width and height values as props.

-

ℹ️ Width and height are undefined during the during the initial render (including server-rendering).

-
- +None #### Optional props @@ -102,6 +85,26 @@ in browsers/environments that do not support the ResizeObserver API tagName

Optional HTML tag name for root HTMLElement; defaults to "div".

+ + + + Child +

Child component to be passed the available width and height values as props. +@deprecated Use the ChildComponent or renderProp props instead.

+ + + + ChildComponent +

Child component to be passed the available width and height values as props.

+

ℹ️ Use renderProp instead if you need access to local state.

+

⚠️ Width and height are undefined during the during the initial render (including server-rendering).

+ + + + renderProp +

Render prop to be passed the available width and height values as props.

+

ℹ️ Use ChildComponent instead for better memoization if you do not need access to local state.

+

⚠️ Width and height are undefined during the during the initial render (including server-rendering).

diff --git a/integrations/vite/src/main.tsx b/integrations/vite/src/main.tsx index 30740b3..a5e9ad0 100644 --- a/integrations/vite/src/main.tsx +++ b/integrations/vite/src/main.tsx @@ -3,12 +3,14 @@ import { createRoot } from "react-dom/client"; import { BrowserRouter, Route, Routes } from "react-router"; import "./index.css"; import { Home } from "./routes/Home"; +import { ScrollingDomState } from "./routes/ScrollingDomState"; createRoot(document.getElementById("root")!).render( } /> + } /> diff --git a/integrations/vite/src/routes/Home.tsx b/integrations/vite/src/routes/Home.tsx index 6b5b509..bd445af 100644 --- a/integrations/vite/src/routes/Home.tsx +++ b/integrations/vite/src/routes/Home.tsx @@ -3,22 +3,25 @@ import { useLayoutEffect, useMemo, useState, - type FunctionComponent + type FunctionComponent, + type ReactNode } from "react"; import { createPortal } from "react-dom"; +import { useSearchParams } from "react-router"; import { AutoSizer, type AutoSizerBox, type Size } from "react-virtualized-auto-sizer"; import { Children, type SizeProps } from "../components/Children"; -import { useSearchParams } from "react-router"; + +export type ChildProp = "Child" | "ChildComponent" | "renderProp"; export function Home() { const [params] = useSearchParams(); const box = (params.get("box") || undefined) as AutoSizerBox | undefined; + const childProp = (params.get("childProp") || "ChildComponent") as ChildProp; const style = params.get("style") || ""; - console.log("Home:", JSON.stringify({ box, style }, null, 2)); const [container] = useState(() => { const div = document.createElement("div"); @@ -40,7 +43,7 @@ export function Home() { const [commits, setCommits] = useState([]); const [onResizeCalls, setOnResizeCalls] = useState([]); - const Child = useMemo>( + const ChildComponent = useMemo>( () => ({ height, width }) => ( + ); + break; + } + case "ChildComponent": { + autoSizer = ( + + ); + break; + } + case "renderProp": { + autoSizer = ( + ( + + )} + /> + ); + break; + } + } + return (
-