βοΈ To return in jsx, react must be imported but no need to in next.js.
βοΈ <Fragment/> </>
When using such functions like key in empty-shortcut markup, it doesn't work:< key = {el.index}
.
But by using fragments, it works: <Fragment key={el.index}>
.
βοΈ readOnly={!!props.data?.fetchBoard.writer}
!!Name --> false --> true
!Name => not Name
--> !!Name => not Name => Name
βοΈ Refactoring
import {Modal} from 'antd'
export default function ModalAlertPage(){
const onClickSuccessButton = () => {
Modal.success({content: "Upload Successful"})
}
const onClickFailButton = () => {
Modal.error({content: "Upload Failure"})
}
return(
<div>
<button onClick={onClickSuccessButton}>Successfully Uploaded Button </button>
<button onClick={onClickFailButton}>Upload Failure Button</button>
</div>
)
}
import React, { useState } from 'react';
import { Modal, Button } from 'antd';
export default function ModalCustomPage(){
const [isModalVisible, setIsModalVisible] = useState(false);
const [_,setPassword] = useState()
//since password isn't used, it can be canceled and replace it to underbar.
const showModal = () => {
setIsModalVisible(true);
//modal appears (true)
};
const handleOk = () => {
setIsModalVisible(false);
//modal disappears when hit ok
};
const handleCancel = () => {
setIsModalVisible(false);
//modal disapears when hit cancel
};
const onChangePassword =(event: ChangeEvent<HTMLInputElement>) => {
setPassword(event.target.value)
}
return (
<>
<Button type="primary" onClick={showModal}>Open Modal</Button>
<Modal title="Password" visible={isModalVisible} onOk={handleOk} onCancel={handleCancel}>
Enter Your Password: <input type="password" onChange={onChangePassword}/>
</Modal>
</>
);
};
import React, {useState } from 'react';
import { Modal, Button } from 'antd';
import DaumPostcode from 'react-daum-postcode';
export default function ModalAddressPage(){
const [isModalVisible, setIsModalVisible] = useState(false);
const [address, setAddress] = useState("")
const [zonecode, setZonecode] = useState("")
const showModal = () => {
setIsModalVisible(true);
};
const handleOk = () => {
setIsModalVisible(false);
};
const handleCancel = () => {
setIsModalVisible(false);
};
const onCompleteDaumPostCode = (data: any) =>{
setAddress(data.address)
setZonecode(data.zonecode)
console.log(data)
setIsModalVisible(false)
}
return (
<>
<Button type="primary" onClick={showModal}>Search for Zip Code</Button>
{isModalVisible && (<Modal title="Address" visible={true} onOk={handleOk} onCancel={handleCancel}>
<DaumPostcode onComplete={onCompleteDaumPostCode}/>
</Modal>
)}
</>
);
};
import { useState } from "react"
export default function StatePrevPage(){
const [count, setCount] = useState(0)
const onClickCountUp =() => {
setCount(count + 1)
}
return (
<div>
<div>Current Count: {count}</div>
<button onClick={onClickCountUp}>Count Up</button>
</div>
)
}
const [count, setCount] = useState(0)
~
setCount(count + 1);
When the user types 0 in the intial value in useState ==> no error.
But when the user doesn't type anything in the initial value in useState, error occurs.
REASON:
setCount(count + 1)
setCount(count + 1)
setCount(count + 1)
setCount(count + 1)
setCount(count + 1)
setCount(count + 1)
setCount(count + 1)
(count(0) + 1) --> count still 0
To make that code upside to be working, the user must use prev method.
setCount((prev) => prev + 1)
setCount((prev) => prev + 1)
setCount((prev) => prev + 1)
setCount((prev) => prev + 1)
setCount((prev) => prev + 1)
Prev is original count value. If there is any saved values inside count, it is accumulating the saved values inside the pre-saving area.
To be specific,
In the middle of commiting the code, husky takes away the code and checks whether the code is available to commit.
Download
yarn add husky@4 --dev
--> When the user wants to download specific data of extention, @Number at the end of the program name.
Reverse function literally reverses the array.
function solution(n) {
const answer = [];
n = n.toString();
for (let i = 0; i < n.length; i++) {
answer.push(Number(n[i]));
}
return answer.reverse();
}