작성
·
430
·
수정됨
0
안녕하세요! 질문 입력 컴포넌트 강의를 듣던 중 toast 처리부터 아래와 같은 오류가 납니다.또한
Anonymous 버튼도 실행이 되지 않습니다.
어떤 문제 일까요?
import { ServiceLayout } from '@/components/service_layout';
import { useAuth } from '@/contexts/auth_user.context';
import { Avatar, Box, Button, Flex, FormControl, FormLabel, Switch, Text, Textarea, useToast } from '@chakra-ui/react';
import { NextPage } from 'next';
import { useState } from 'react';
import ResizeTextarea from 'react-textarea-autosize';
const userInfo = {
uid: 'test',
email: 'cccodus313@gmail.com',
displayName: 'park chae yeon',
photoURI: '',
};
const UserHomePage: NextPage = function () {
const [message, setMessage] = useState('');
const [isAnonymous, setAnonymous] = useState(true);
const toast = useToast();
const { authUser } = useAuth();
return (
<ServiceLayout title="user home" minH="100vh" backgroundColor="gray.50">
;
<Box maxW="md" mx="auto" pt="6">
<Box borderWidth="1px" borderRadius="lg" overflow="hidden" mb="2" bg="white">
<Flex p="6">
<Avatar size="lg" src={userInfo.photoURI} mr="2" />
<Flex direction="column" justify="center">
<Text fontSize="md">{userInfo.displayName}</Text>
<Text fontSize="xs">{userInfo.email}</Text>
</Flex>
</Flex>
</Box>
<Box borderWidth="1px" borderRadius="lg" overflow="hidden" mb="2" bg="white">
<Flex align="center" p="2">
<Avatar
size="xs"
src={isAnonymous ? 'https://bit.ly/broken-link' : authUser?.photoURL ?? 'https://bit.ly/broken-link'}
mr="2"
/>
<Textarea
bg="gray.100"
border="none"
boxShadow="none !important"
placeholder="어떤 이야기를 나누고 싶나요?"
borderRadius="md"
resize="none"
minH="unset"
overflow="hidden"
fontSize="xs"
mr="2"
minRows={1}
maxRows={7}
as={ResizeTextarea}
value={message}
onChange={(e) => {
if (e.target.value) {
const lineCount = (e.target.value.match(/[^\n]*\n[^\n]*/gi)?.length ?? 1) + 1;
if (lineCount > 7) {
toast({
title: '최대 7줄까지만 입력가능합니다',
position: 'top-right',
});
return;
}
}
setMessage(e.target.value);
}}
/>
<Button
disabled={message.length === 0}
bgColor="#FFB86C"
color="white"
colorScheme="yellow"
variant="solid"
size="sm"
>
등록
</Button>
</Flex>
<FormControl display="flex" alignItems="center" mt="1" mx="2" pb="2">
<Switch
size="sm"
colorScheme="orange"
id="anonymous"
mr="1"
isChecked={isAnonymous}
onChange={() => {
if (authUser === null) {
toast({
title: '로그인이 필요합니다',
position: 'top-right',
});
return;
}
setAnonymous((prev) => !prev);
}}
/>
<FormLabel htmlFor="anonymous" mb="0" fontSize="xx-small">
Anonymous
</FormLabel>
</FormControl>
</Box>
</Box>
</ServiceLayout>
);
};
export default UserHomePage;