mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 13:43:15 +02:00
feat: add context
This commit is contained in:
parent
3cdd5ca8b4
commit
69ecbea0be
@ -7,10 +7,20 @@ import {
|
|||||||
Outlet,
|
Outlet,
|
||||||
} from "react-router-dom";
|
} from "react-router-dom";
|
||||||
import React from 'react';
|
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<Navbar bg="light" expand="lg">
|
<Navbar bg="light" expand="lg">
|
||||||
<Container>
|
<Container>
|
||||||
<Navbar.Brand href="/">Lab 3</Navbar.Brand>
|
<Navbar.Brand href="/">Lab 3</Navbar.Brand>
|
||||||
@ -27,8 +37,11 @@ export default function App() {
|
|||||||
|
|
||||||
</Navbar>
|
</Navbar>
|
||||||
<Outlet />
|
<Outlet />
|
||||||
|
|
||||||
</div>
|
</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 React from 'react';
|
||||||
|
import loginContext from '../context.context';
|
||||||
|
|
||||||
export default class Blog extends React.Component {
|
export default class Blog extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
login: "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
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!");
|
alert("This login: \"" + this.state.login + "\" does not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
} if(allData[0].password !== this.state.password)
|
||||||
if(allData[0].password !== this.state.password)
|
|
||||||
{
|
{
|
||||||
alert("Wrong password!");
|
alert("Wrong password!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
return this.state.login;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user