Skip to content

Instantly share code, notes, and snippets.

@mtavkhelidze
Last active November 17, 2024 05:43
Show Gist options
  • Save mtavkhelidze/6a54189cda2eb93373fc307857f4f202 to your computer and use it in GitHub Desktop.
Save mtavkhelidze/6a54189cda2eb93373fc307857f4f202 to your computer and use it in GitHub Desktop.
A component for protection of routes, for example when using `wouter`
import React, { type PropsWithChildren } from "react";
type Props = {
with: () => boolean;
} & PropsWithChildren
const Protected: React.FC<Props> = props =>
props.with() ? <>{props.children}</> : <UserLogin />;
// <Protected with={()-> isLoggedIn}><Profile/></Protected>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment