feat: add context

This commit is contained in:
PolishPigeon 2022-06-13 01:11:46 +02:00
parent 3cdd5ca8b4
commit 69ecbea0be
4 changed files with 32 additions and 5 deletions

View File

@ -7,10 +7,20 @@ import {
Outlet,
} from "react-router-dom";
import React from 'react';
import loginContext from './context.context';
export default function App() {
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
login: "",
};
}
render() {
return (
<div>
<Navbar bg="light" expand="lg">
<Container>
<Navbar.Brand href="/">Lab 3</Navbar.Brand>
@ -27,8 +37,11 @@ export default function App() {
</Navbar>
<Outlet />
</div>
);
}
}
}

View File

@ -0,0 +1,5 @@
import { createContext } from "react";
const loginContext = createContext('test');
export default loginContext;

View File

@ -1,9 +1,18 @@
import Login from './login';
import React from 'react';
import loginContext from '../context.context';
export default class Blog extends React.Component {
constructor(props) {
super(props);
this.state = {
login: "",
};
}
render() {
return (
<div> hello </div>
<div> You are not logged in {this.state.login} </div>
);
}
}

View File

@ -74,11 +74,11 @@ export default class Login extends React.Component {
{
alert("This login: \"" + this.state.login + "\" does not exist!");
return;
}
if(allData[0].password !== this.state.password)
} if(allData[0].password !== this.state.password)
{
alert("Wrong password!");
return;
}
return this.state.login;
}
}