Open EYEG opened 5 months ago
Q1. useMemo의 장점을 서술하세요. (5점)
이미 메모리(RAM)에 저장된 코드를 다시 사용할 수 있다. (메모리 낭비 X)
emotion.js 를 통해 다음과 같이 미디어 쿼리를 설정했습니다.
import { css } from '@emotion/react'
const breakpoints = [576, 768, 992, 1200]
const mq = breakpoints.map(bp => `@media (min-width: ${bp}px)`)
render(
<div>
<div
css={{
color: 'green',
[mq[0]]: {
color: 'gray'
},
[mq[1]]: {
color: 'hotpink'
}
}}
>
Some text!
</div>
<p
css={css`
color: green;
${mq[0]} {
color: gray;
}
${mq[1]} {
color: hotpink;
}
`}
>
Some other text!
</p>
</div>
)
하지만, 코드길이를 축약할 수 있는 방법이 있는데 그것은 무엇일까요?
styled-components에서 스타일 코드 여러줄을 props에 따라 넣어주어야 할때는 css를 styled-components에서 불러와야 합니다. 사실 css를 사용하지 않고 문자열로 넣어도 됩니다. 하지만 이렇게 구현했을때의 문제점은 무엇일까용
${props => props.inverted && `color: white; border: 1px solid red;`}
아래는 styled-components를 사용하는 예시이다. 다음 중 불가능한 것은?
import styled from 'styled-components';
const MyComponent = styled.div`
font-size: 2rem;
`;
const MyInput = styled('input')`
background: gray;
`
const StyledLink = styled(Link)`
color:blue;
facepaint는 ____ 에서만 동작합니다.
import React, { useReducer } from 'react';
const counterReducer = (state, action) => {
switch (action.type) {
case 'INCREMENT':
return { count: state.count + 1 };
case 'DECREMENT':
return { count: state.count - 1 };
default:
return state;
}
};
const initialState = { count: 0 };
const Counter = () => {
const [state, dispatch] = useReducer(counterReducer, initialState);
const increment = () => dispatch({ type: 'INCREMENT' });
const decrement = () => dispatch({ type: 'DECREMENT' });
return (
<div>
<p>Count: {state.count}</p>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
};
export default Counter;
useReducer를 사용할 때, dispatch 함수의 역할은? 1) 상태를 갱신하기 위해 액션을 전달하는 함수 2) 상태를 반환하는 함수 3) 이벤트 핸들러 4) 네트워크 요청을 보내는 함수
useReducer를 사용하여 상태를 갱신할 때, 어떤 형식의 객체를 dispatch 함수에 전달해야할까용 1) 숫자 2) 문자열 3) 불리언 4) 액션 객체
useReducer를 사용할 때, 리듀서 함수에서 반환하는 값은? 1) 새로운 상태 2) 이전 상태 3) 액션 객체 4) dispatch 함수
아래 코드에 대하여 useMemo, useCallback, styled-components의 각각 어떤 동작을 하는지 설명해보기