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-routerto handle routing, if your are using a different router you can use theuseOddContexthook directly.It routes to the
redirectTopath if the user is not logged in or whenredirectIfFoundis set totrueroutes toredirectToif user is logged in.Example
Example