1+ /* eslint-disable react/jsx-no-bind */
12/* eslint-disable object-shorthand */
2- import React , { useState , useRef } from 'react' ;
3+ import React , { useState , useRef , useCallback } from 'react' ;
34import { useSetRecoilState , useRecoilValue } from 'recoil' ;
45
56import roomDocumentIdState from '@atoms/room-document-id' ;
@@ -29,7 +30,7 @@ function RoomModal() {
2930 const [ isAnonymous , setIsAnonymous ] = useState ( false ) ;
3031 const inputRef = useRef < HTMLInputElement > ( null ) ;
3132
32- const submitButtonHandler = async ( ) => {
33+ const submitButtonHandler = useCallback ( async ( ) => {
3334 try {
3435 const roomInfo = {
3536 type : roomType ,
@@ -50,7 +51,7 @@ function RoomModal() {
5051 if ( error . name === 'NotAllowedError' ) setToastList ( toastMessage . roomAllowMicDanger ( ) ) ;
5152 else setToastList ( toastMessage . roomCreateDanger ( ) ) ;
5253 }
53- } ;
54+ } , [ roomType ] ) ;
5455
5556 const inputHandler = ( ) => {
5657 setIsDisabled ( ! inputRef . current ?. value ) ;
@@ -64,38 +65,44 @@ function RoomModal() {
6465 setRoomType ( checkBoxName ) ;
6566 } ;
6667
67- const randomlyAssignedHandler = async ( ) => {
68+ const randomlyAssignedHandler = useCallback ( async ( ) => {
6869 const roomDocumentId = await getRandomRoomDocumentId ( ) ;
6970 if ( roomDocumentId === 'NO_ROOM' ) {
7071 setToastList ( toastMessage . roomMatchingDanger ( ) ) ;
7172 } else {
7273 setRoomDocumentId ( roomDocumentId ) ;
7374 setRoomView ( 'selectModeView' ) ;
7475 }
75- } ;
76+ } , [ ] ) ;
77+
78+ const CheckBoxs = React . memo ( ( ) => (
79+ < CheckboxLayout >
80+ < RoomTypeCheckBox checkBoxName = "public" onClick = { roomTypeHandler . bind ( null , 'public' ) } roomType = { roomType } />
81+ < RoomTypeCheckBox checkBoxName = "closed" onClick = { roomTypeHandler . bind ( null , 'closed' ) } roomType = { roomType } />
82+ </ CheckboxLayout >
83+ ) ) ;
84+
85+ const Buttons = React . memo ( ( ) => (
86+ < ButtonLayout >
87+ < DefaultButton buttonType = "secondary" size = "medium" onClick = { submitButtonHandler } isDisabled = { isDisabled } >
88+ Let's Go
89+ </ DefaultButton >
90+ < DefaultButton buttonType = "thirdly" size = "medium" onClick = { randomlyAssignedHandler } >
91+ Randomly assigned
92+ </ DefaultButton >
93+ </ ButtonLayout >
94+ ) ) ;
7695
7796 return (
7897 < >
7998 < h2 > Let's have fun together! </ h2 >
80- < CheckboxLayout >
81- { /* eslint-disable-next-line react/jsx-no-bind */ }
82- < RoomTypeCheckBox checkBoxName = "public" onClick = { roomTypeHandler . bind ( null , 'public' ) } roomType = { roomType } />
83- { /* eslint-disable-next-line react/jsx-no-bind */ }
84- < RoomTypeCheckBox checkBoxName = "closed" onClick = { roomTypeHandler . bind ( null , 'closed' ) } roomType = { roomType } />
85- </ CheckboxLayout >
99+ < CheckBoxs />
86100 < AnonymousCheckBox checked = { isAnonymous } onChange = { checkboxHandler } roomType = { roomType } text = "Allow anonymous ?" />
87101 < CustomTitleForm >
88102 < TitleInputbarLabel > Add a Room Title</ TitleInputbarLabel >
89103 < TitleInputbar ref = { inputRef } onChange = { inputHandler } data-testid = "TitleInputbar" />
90104 </ CustomTitleForm >
91- < ButtonLayout >
92- < DefaultButton buttonType = "secondary" size = "medium" onClick = { submitButtonHandler } isDisabled = { isDisabled } >
93- Let's Go
94- </ DefaultButton >
95- < DefaultButton buttonType = "thirdly" size = "medium" onClick = { randomlyAssignedHandler } >
96- Randomly assigned
97- </ DefaultButton >
98- </ ButtonLayout >
105+ < Buttons />
99106 </ >
100107 ) ;
101108}
0 commit comments