File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import React from 'react' ;
22import Navigation from './components/Navigation'
3+ import AuthContextProvider from './contexts/AuthContext' ;
4+ import Prueba from './components/Prueba' ;
35
46function App ( ) {
57 return (
68 < React . Fragment >
7- < Navigation />
8- < h1 > Hola Mundo</ h1 >
9+ < AuthContextProvider >
10+ < Navigation />
11+ < h1 > Hola Mundo</ h1 >
12+ < Prueba />
13+ </ AuthContextProvider >
914 </ React . Fragment >
1015 ) ;
1116}
Original file line number Diff line number Diff line change 1- import React , { useState } from 'react' ;
1+ import React , { useState , useContext } from 'react' ;
2+ import { AuthContext } from '../../contexts/AuthContext'
3+
24import {
35 Collapse ,
46 Navbar ,
@@ -16,6 +18,7 @@ import {
1618
1719const Navigation = ( props ) => {
1820 const [ isOpen , setIsOpen ] = useState ( false ) ;
21+ const { token} = useContext ( AuthContext ) ;
1922
2023 const toggle = ( ) => setIsOpen ( ! isOpen ) ;
2124
@@ -50,7 +53,7 @@ const Navigation = (props) => {
5053 </ DropdownMenu >
5154 </ UncontrolledDropdown >
5255 </ Nav >
53- < NavbarText > Simple Text </ NavbarText >
56+ < NavbarText > { token } </ NavbarText >
5457 </ Collapse >
5558 </ Navbar >
5659 </ div >
Original file line number Diff line number Diff line change 1+ import React , { useContext } from "react" ;
2+ import { AuthContext } from '../../contexts/AuthContext' ;
3+
4+ const Prueba = ( ) => {
5+ const { token, setToken} = useContext ( AuthContext ) ;
6+ return (
7+ < React . Fragment >
8+ < h2 > El contenido del token es: { token } </ h2 >
9+ < input type = "text" onChange = { ( e ) => setToken ( e . target . value ) } />
10+ </ React . Fragment >
11+ ) ;
12+ }
13+
14+ export default Prueba ;
Original file line number Diff line number Diff line change 1+ import React , { createContext , useState } from 'react' ;
2+
3+ export const AuthContext = createContext ( ) ;
4+
5+ const AuthContextProvider = ( props ) => {
6+ const [ token , setToken ] = useState ( '' ) ;
7+
8+ return (
9+ < AuthContext . Provider value = { {
10+ token, setToken
11+ } } >
12+ { props . children }
13+ </ AuthContext . Provider >
14+ )
15+ } ;
16+
17+ export default AuthContextProvider ;
18+
19+ /*
20+ <Proveedor>
21+ <Navbar>
22+ <Body>
23+ <Footer>
24+ <Proveedor>
25+ */
You can’t perform that action at this time.
0 commit comments