diff --git a/src/App.js b/src/App.js
index e9c90db..2c7cecb 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,41 +1,54 @@
-import React, { Component } from 'react';
-import AddContact from './AddContact';
-import 'bootstrap/dist/css/bootstrap.min.css';
-import './App.css';
+import React, { useState } from "react";
+import AddContact from "./AddContact";
+import "bootstrap/dist/css/bootstrap.min.css";
+import "./App.css";
-export default class App extends Component {
+// export default class App extends Component {
+// constructor(props) {
+// super(props);
+// this.state = { newContactClicked: false };
+// this.handleNewContact = this.handleNewContact.bind(this);
+// }
- constructor(props) {
- super(props);
- this.state = {newContactClicked: false};
- this.handleNewContact = this.handleNewContact.bind(this);
- }
+// handleNewContact(event) {
+// event.preventDefault();
+// this.setState({ newContactClicked: true });
+// }
- handleNewContact(event) {
- event.preventDefault();
- this.setState({newContactClicked: true});
- }
+export default function App() {
+ const [newContactClicked, setnewContact] = useState(false);
- render() {
- const newIsClicked = this.state.newContactClicked;
- return (
+ const handleNewContact = (event) => {
+ event.preventDefault();
+ setnewContact(() => {
+ return { newContactClicked: true };
+ });
+ };
+
+ const newIsClicked = newContactClicked;
+ return (
-
-
-
-
-
-
- {newIsClicked &&
}
-
{JSON.stringify(this.state, null, 2)}
+
+
+
+
+
+
+ {newIsClicked &&
}
+ {/*
{JSON.stringify(this.state, null, 2)}
*/}
+
-
-
-
+
+
- );
- }
+ );
}
diff --git a/src/Chat.js b/src/Chat.js
index ddd2c11..83b1802 100644
--- a/src/Chat.js
+++ b/src/Chat.js
@@ -1,37 +1,62 @@
-import React, { Component } from 'react';
-import Messages from './Messages';
-import 'bootstrap/dist/css/bootstrap.min.css';
+import React, { useState } from "react";
+import Messages from "./Messages";
+import "bootstrap/dist/css/bootstrap.min.css";
-export default class Chat extends Component {
+// export default class Chat extends Component {
- constructor(props) {
- super(props);
- this.state = {message: 'Type a message', messages: [], sendClicked: false}
- this.handleChange = this.handleChange.bind(this);
- this.handleSubmit = this.handleSubmit.bind(this);
- }
+// constructor(props) {
+// super(props);
+// this.state = {message: 'Type a message', messages: [], sendClicked: false}
+// this.handleChange = this.handleChange.bind(this);
+// this.handleSubmit = this.handleSubmit.bind(this);
+// }
- handleChange(event) {
- this.setState({message: event.target.value});
- }
+export default function Chat() {
+ const [state, setState] = useState({
+ message: "Type a message",
+ messages: [],
+ sendClicked: false,
+ });
- handleSubmit(event) {
- event.preventDefault();
- this.setState({message: '', messages: [...this.state.messages, this.state.message], sendClicked: true});
- }
+ const handleChange = (event) => {
+ setState((todo) => {
+ return { message: event.target.value };
+ });
+ };
- render() {
- return (
+ const handleSubmit = (event) => {
+ event.preventDefault();
+ setState(() => {
+ return {
+ message: "",
+ messages: [...state.messages, state.message],
+ sendClicked: true,
+ };
+ });
+ };
+
+ return (
-
-
-
{JSON.stringify(this.state, null, 2)}
+
+
+ {/*
{JSON.stringify(this.state, null, 2)}
*/}
- );
- }
+ );
}
diff --git a/src/Contacts.js b/src/Contacts.js
index 90b2c40..d58ecac 100644
--- a/src/Contacts.js
+++ b/src/Contacts.js
@@ -1,40 +1,52 @@
-import React, { useState } from 'react';
-import Chat from './Chat';
-import 'bootstrap/dist/css/bootstrap.min.css';
+import React, { useState } from "react";
+import Chat from "./Chat";
+import "bootstrap/dist/css/bootstrap.min.css";
const Contacts = (props) => {
- const [state,setState] = useState({
- chatClicked:false,
- chatListClicked:[]
- });
+ const [state, setState] = useState({
+ chatClicked: false,
+ chatListClicked: [],
+ });
- const handleChat = (event) => {
- event.preventDefault();
- setState(prevValue => {
- return{
- chatClicked: true,
- chatListClicked:[...prevValue.chatListClicked, prevValue.chatClicked]
- }
- });
- }
+ const handleChat = (event) => {
+ event.preventDefault();
+ setState((prevValue) => {
+ return {
+ chatClicked: true,
+ chatListClicked: [
+ ...prevValue.chatListClicked,
+ prevValue.chatClicked,
+ ],
+ };
+ });
+ };
- return (
+ return (
-
- {state.chatClicked && }
- {props.names.map((name, i) =>
- -
-
-
- )}
-
-
{JSON.stringify(this.state, null, 2)}
+
+ {state.chatClicked && }
+ {props.names.map((name, i) => (
+ -
+
+
+ ))}
+
+ {/*
{JSON.stringify(this.state, null, 2)}
*/}
- );
-}
+ );
+};
export default Contacts;