useEffect(() => {
let stopGettingAfterUnmount = false;
const getTodo = async () => {
await axios
.get("/api/todo", {
headers: {
"Content-Type": "application/json",
},
params: { userId },
})
.then((response) => {
if (stopGettingAfterUnmount) return;
setTodos(response.data);
});
};
getTodo();
return () => {
stopGettingAfterUnmount = true;
};
}, [userId]);
let cleanupFunction = false;
return () => cleanupFunction = true;
await Todo.find({}).lean()
{Object.keys(profile.contacts).map((key) => {
return (
<React.Fragment>
<TextField
key={key}
className={classes.gutters}
margin='dense'
fullWidth
variant='outlined'
id='standard-basic'
name={`contacts.${key}`}
label={key}
value={`values.contacts.${key}`}
onBlur={handleBlur}
onChange={handleChange}
error={`touched.contacts?.${key}` && Boolean(`errors.contacts?.${key}`)}
helperText={`touched.contacts?.${key}` && `errors.contacts?.${key}`}
/>
</React.Fragment>
)
})}
import React from 'react';
import classes from './Dialogs.module.css';
import DialogItem from "./DialogItem/DialogItem";
import Message from "./Message/Message";
import {Redirect} from "react-router-dom";
import {Field, Form, Formik} from 'formik';
const Dialogs = (props) => {
let state = props.dialogsPage;
let dialogsElements = state.dialogs
.map(el => <DialogItem name={el.name} key={el.id} id={el.id} avatar={el.avatar}/>);
let messagesElements = state.messages
.map(el => <Message message={el.message} key={el.id}/>);
if (!props.isAuth) return <Redirect to={"/login"}/>;
return (
<div className={classes.dialogs}>
<div className={classes.dialogsItems}>
{dialogsElements}
</div>
<div className={classes.messages}>
<div>{messagesElements}</div>
</div>
<AddMessageForm sendMessage={props.sendMessage}/>
</div>
)
}
const AddMessageForm = (props) => {
const initialValues = {
newMessageBody: ''
}
const onSubmit = values => {
props.sendMessage(values.newMessageBody);
console.log('запись', values)
}
return (
<Formik initialValues={initialValues} onSubmit={onSubmit}>
<Form>
<div>
<div>
<Field as='textarea'
id='newMessageBody'
name='newMessageBody'/>
</div>
<button type='submit'>Submit</button>
</div>
</Form>
</Formik>
)
}
export default Dialogs;