@selfcommunity/react-core
Version:
React Core Components useful for integrating UI Community components (react-ui).
57 lines (50 loc) • 1.55 kB
TypeScript
/// <reference types="react" />
import { SCSessionType } from '../types';
import { SCAuthTokenType } from '@selfcommunity/types';
/**
* @hidden
* We have complex state logic that involves multiple sub-values,
* so useReducer is preferable to useState.
* Define all possible auth action types label
* Use this to export actions and dispatch an action
*/
export declare const userActionTypes: {
LOGIN_LOADING: string;
LOGIN_SUCCESS: string;
LOGIN_FAILURE: string;
LOGOUT: string;
REFRESH_TOKEN_SUCCESS: string;
REFRESH_TOKEN_FAILURE: string;
REFRESH_SESSION: string;
UPDATE_USER: string;
};
/**
:::info
This component is used to navigate through the application.
:::
#### Usage
In order to use router you need to import this components first:
```jsx
import {SCRoutingContextType, useSCRouting, Link, SCRoutes} from '@selfcommunity/react-core';
````
:::tip Usage Example:
```jsx
const scRoutingContext: SCRoutingContextType = useSCRouting();
<Button component={Link} to={scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, {id: user.id})>Go to profile</Button>
````
or
```jsx
const scRoutingContext: SCRoutingContextType = useSCRouting();
<Link to={scRoutingContext.url('profile', {id: user.id})}>Go to profile</Link>
````
:::
* @param initialSession
*/
export default function useAuth(initialSession: SCSessionType): {
state: any;
dispatch: import("react").Dispatch<any>;
helpers: {
refreshSession: () => Promise<SCAuthTokenType>;
logoutSession: () => void;
};
};