Hook to access the ODD program and session from the OddContextProvider.
OddContextProvider
It uses preact-router to handle routing, if your are using a different router you can use the useOddContext hook directly.
preact-router
useOddContext
It routes to the redirectTo path if the user is not logged in or when redirectIfFound is set to true routes to redirectTo if user is logged in.
redirectTo
redirectIfFound
true
// login.jsximport { useOdd } from '@oddjs/preact/router'const { isLoading, login } = useOdd({ redirectTo: '/', redirectIfFound: true, }) Copy
// login.jsximport { useOdd } from '@oddjs/preact/router'const { isLoading, login } = useOdd({ redirectTo: '/', redirectIfFound: true, })
// home.jsximport { useOdd } from '@oddjs/preact/router'const { isLoading, logout } = useOdd({ redirectTo: '/login', }) Copy
// home.jsximport { useOdd } from '@oddjs/preact/router'const { isLoading, logout } = useOdd({ redirectTo: '/login', })
Optional
Generated using TypeDoc
Hook to access the ODD program and session from the
OddContextProvider
.It uses
preact-router
to handle routing, if your are using a different router you can use theuseOddContext
hook directly.It routes to the
redirectTo
path if the user is not logged in or whenredirectIfFound
is set totrue
routes toredirectTo
if user is logged in.Example
Example