Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoginProvider.tsx 640B

123456789101112131415161718192021222324252627
  1. import React, { useState } from 'react';
  2. import { LoginContext, LoginContextType } from '../../context/loginContext';
  3. type Props = {
  4. children: React.ReactChild;
  5. initialToken: string | undefined;
  6. };
  7. export default function LoginProvider(props: Props) {
  8. const setLogin = (token: string | undefined) => {
  9. setLoginState((prevState) => ({
  10. ...prevState,
  11. token,
  12. }));
  13. };
  14. const [loginState, setLoginState] = useState<LoginContextType>({
  15. token: props.initialToken,
  16. setLogin: setLogin,
  17. });
  18. return (
  19. <LoginContext.Provider value={loginState}>
  20. {props.children}
  21. </LoginContext.Provider>
  22. );
  23. }