Skip to content

Commit

Permalink
Estado Global (#75)
Browse files Browse the repository at this point in the history
* Estado Global

Franco, esto medio que ya quedó, pero estoy teniendo unos problemas. La página no se está renderizando correctamente.

* Nombre de variable cambiado

{contenido} por {children}
  • Loading branch information
JLeonN authored Apr 23, 2024
1 parent 1e35f73 commit 36adb12
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
8 changes: 0 additions & 8 deletions frontend/src/API/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ const api = axios.create();

const token = import.meta.env.VITE_JWT;

// const tokenSesion = () => {
// const obtenerToken = localStorage.getItem("token");
// const tokenn = JSON.parse(obtenerToken);
// return tokenn;
// };
// const lol = tokenSesion();
// console.log(lol.token);

const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ span {
max-width: 500px;
margin-left: auto;
margin-right: auto;
margin-top: 1.5rem;
}
.ListaTitulos:hover {
color: var(--hoverTexto);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { EstadoGlobal } from "./Context/EstadoGlobal";
import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css";
import "bootstrap/dist/js/bootstrap.min.js";
import NavBar from "./Componentes/NavBar/NavBar";
import Estructura from "./Componentes/Estructura";
import { PruebaContext } from "./Context/Context";

function App() {
return (
<>
<PruebaContext.Provider value="yoooo">
<EstadoGlobal>
<NavBar />
<Estructura />
</PruebaContext.Provider>
</EstadoGlobal>
</>
);
}
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/Context/Context.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createContext } from "react";
import { createContext, useContext } from "react";

export const PruebaContext = createContext(null);
export const TContext = createContext();

export const useEstadoGlobal = () => useContext(TContext);
23 changes: 23 additions & 0 deletions frontend/src/Context/EstadoGlobal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useState } from "react";
import { TContext } from "./Context";

const tokenSesion = () => {
const obtenerToken = localStorage.getItem("token");
const tokenn = JSON.parse(obtenerToken);
return tokenn;
};

export const EstadoGlobal = ({ children }) => {
const [token, setToken] = useState(null);
console.log("token actual", token)

useEffect(() => {
setToken(tokenSesion());
},[]);

return (
<TContext.Provider value={{ token, setToken }}>
{children}
</TContext.Provider>
);
};
13 changes: 0 additions & 13 deletions frontend/src/Pagina/Inicio.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@ import { useCowboyDelDia } from "../Hooks/useCowboyDelDia";
import Tarjeta from "../Componentes/Tarjeta/Tarjeta";
import Carga from "../Pagina/Errores/Carga";


import { useContext } from "react";
import { PruebaContext } from "../Context/Context";



const Inicio = () => {
const { tonto, carga, errorTonto } = useObtenerTonto();
const { cowboy, errorCowboy } = useCowboyDelDia();


const compartida = useContext(PruebaContext);
console.log(compartida);




if (carga) {
return <Carga />;
}
Expand Down

0 comments on commit 36adb12

Please sign in to comment.