Skip to content

Commit

Permalink
safer
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Dec 29, 2024
1 parent 8869613 commit 07de69f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/react/src/unstable-no-ssr/NoSsr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { NoSsrProps } from './NoSsr.types';
*
* Documentation: [Base UI Unstable No Ssr](https://base-ui.com/react/components/unstable-no-ssr)
*/
function NoSsr(props: NoSsrProps): React.ReactNode {
function NoSsr(props: NoSsrProps): React.JSX.Element {
const { children, defer = false, fallback = null } = props;
const [mountedState, setMountedState] = React.useState(false);

Expand All @@ -33,7 +33,10 @@ function NoSsr(props: NoSsrProps): React.ReactNode {
}
}, [defer]);

return mountedState ? children : fallback;
// TODO casting won't be needed at one point https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65135
// We could replace React.JSX.Element with React.ReactNode.
// But first, we need to bump min typescript support to version to 5.1 and enough people to adopt the above change.
return (mountedState ? children : fallback) as React.JSX.Element;
}

NoSsr.propTypes /* remove-proptypes */ = {
Expand Down

0 comments on commit 07de69f

Please sign in to comment.