mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 17:03:12 +02:00
feat: add context
This commit is contained in:
parent
3cdd5ca8b4
commit
69ecbea0be
@ -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>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
5
EGUI/lab3/src/context.context.jsx
Normal file
5
EGUI/lab3/src/context.context.jsx
Normal file
@ -0,0 +1,5 @@
|
||||
import { createContext } from "react";
|
||||
|
||||
const loginContext = createContext('test');
|
||||
|
||||
export default loginContext;
|
||||
@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user