From 41510627240f3f3b3fc2b99d5ba4b348247ec952 Mon Sep 17 00:00:00 2001 From: lukas Date: Sat, 30 May 2020 19:29:42 +0200 Subject: [PATCH] tabbed app with buttons to switch tab --- .idea/vcs.xml | 6 ++++ src/AlternativeBody.js | 11 +++++++ src/App.css | 37 --------------------- src/App.js | 74 ++++++++++++++++++++++-------------------- src/MainBody.js | 19 +++++++++++ src/Zwei.js | 6 ++-- 6 files changed, 77 insertions(+), 76 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/AlternativeBody.js create mode 100644 src/MainBody.js diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/AlternativeBody.js b/src/AlternativeBody.js new file mode 100644 index 0000000..d353c7a --- /dev/null +++ b/src/AlternativeBody.js @@ -0,0 +1,11 @@ +import * as React from "react"; + +class AlternativeBody extends React.Component{ + render() { + return ( +
Second page!
+ ); + } +} + +export default AlternativeBody; \ No newline at end of file diff --git a/src/App.css b/src/App.css index 78b8850..8b13789 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1 @@ -.App { - text-align: center; -} -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/src/App.js b/src/App.js index 50e5976..502a357 100644 --- a/src/App.js +++ b/src/App.js @@ -1,42 +1,44 @@ import React from 'react'; -import logo from './logo.svg'; import './App.css'; -import ReactDOM from "react-dom"; -import TodoApp from "./Zwei" +import MainBody from "./MainBody"; +import AlternativeBody from "./AlternativeBody" +import ReactDOM from 'react-dom'; -function App() { - return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - - - -
-
- ); +class App extends React.Component { + page1click() { + console.log("click page1"); + + // rerender mainbody space here + ReactDOM.render( + , + document.getElementById("mainbody") + ); + } + + page2click() { + console.log("click page2"); + + // rerender mainbody space here + ReactDOM.render( + , + document.getElementById("mainbody") + ); + } + + render() { + return ( +
+
+ + +
+
+ mimimimimi +
+ +
+ ); + } } export default App; diff --git a/src/MainBody.js b/src/MainBody.js new file mode 100644 index 0000000..8971055 --- /dev/null +++ b/src/MainBody.js @@ -0,0 +1,19 @@ +import React from "react"; + +class MainBody extends React.Component { + render() { + const requestOptions = { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ title: 'React POST Request Example' }) + }; + fetch('https://jsonplaceholder.typicode.com/posts', requestOptions) + .then(response => response.json()) + .then(data => this.setState({ postId: data.id })); + return ( +
Hey from other class
+ ); + } +} + +export default MainBody; \ No newline at end of file diff --git a/src/Zwei.js b/src/Zwei.js index 654e3ef..925a320 100644 --- a/src/Zwei.js +++ b/src/Zwei.js @@ -3,7 +3,7 @@ import React from 'react'; class TodoApp extends React.Component { constructor(props) { super(props); - this.state = { items: [], text: '' }; + this.state = {items: [], text: ''}; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } @@ -12,7 +12,7 @@ class TodoApp extends React.Component { return (

TODO

- +