Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Spring
- reactnative
- codepush
- supabase authentication
- async
- Filter
- 코드푸시
- interface
- generic
- code-push-standalone
- 페이지네이션
- 글또10기x코드트리
- react
- xlsx-js-style
- TS
- 타입스크립트
- array
- supabase 페이지네이션
- supabase auth
- extends
- 스크롤이벤트
- 이진탐색
- Next.js
- app.post
- meatadata
- set
- javascript
- 슬라이딩윈도우
- 상속
- map
Archives
- Today
- Total
rhanziy
리액트 - 함수형 프로그래밍 useConfirm 본문
const useConfirm = (message = "", onConfirm, onCancel) => {
if ( !onConfirm && typeof onConfirm !== "function") {
return;
}
if ( onCancel && typeof onCancel !== "function") {
return;
}
const confirmAction = () => {
if (window.confirm(message)) {
onConfirm();
} else {
onCancel();
}
};
return confirmAction;
};
export default function App() {
const deleteWorld = () => console.log("Deleting the world");
const abort = () => console.log("Aborted");
const confirmDelete = useConfirm("Are you sure", deleteWorld, abort);
return (
<div className="App">
<button onClick={confirmDelete}>Delete the world</button>
</div>
);
}
버튼을 누르면 사용자의 이벤트에 따라 결과 값이 다른 콘솔찍는 코드.
함수형 컴포넌트를 만들어서 모듈화하고 파라미터로 전달된 값을 통해 기능 구현하기.
많이 연습해서 자유자재로 쓸 수 있길 ㅠㅠ
useState와 useEffect를 사용하지않아서 훅이라고 볼 순 없지만! 이런 기본뼈대에 리액트에서 제공하는
여러가지 훅을 조립해서 페이지를 만들어보자.
'React' 카테고리의 다른 글
React - 이미지 넣는 방법 3가지 (0) | 2022.11.22 |
---|---|
리액트 Hooks - useAxios (0) | 2022.05.24 |
리액트 Hooks - useTitle (0) | 2022.05.15 |
리액트 Hooks - useTabs(useState) ...🙄 (0) | 2022.05.10 |
react. react작업 github page로 올리기 (0) | 2022.03.15 |