error message You are loading @emotion/react when it is already loaded. Running multiple instances may cause problems. This can happen if multiple versions are used, or if multiple builds of the same version are used. You have tried to stringify object returned from css function. It isn't supposed to be used directly (e.g. as value of the className prop), but rather handed to emotion so it can handle it (e.g. as value of css prop). .. HTML 에서 CSS 적용했지만 안된 코드 보니 You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle 태그에 들어가져 있었음 |
아래처럼 작성했으나 적용 안됨
import { css, jsx } from '@emotion/react';
...
<div
css={css`
display: flex;
justify-content: flex-end;
`}
>
검색 후
babel.config.js
module.exports = {
presets: [
'@babel/preset-env',
[
'@babel/preset-react',
{ runtime: 'automatic', importSource: '@emotion/react' },
],
['@emotion/babel-preset-css-prop'],
],
plugins: ['@emotion/babel-plugin'],
};
craco.config.js
module.exports = {
..
babel: {
presets: ['@emotion/babel-preset-css-prop'],
plugins: [...emotionBabelPreset.plugins],
},
package.json(없는건 추가설치)
"@emotion/babel-plugin": "^11.10.6",
"@emotion/babel-preset-css-prop": "^11.10.0",
"@emotion/css": "^11.10.6",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
이렇게 했으나 안되고 결국 사용하는 해당파일 상단 import위에 이렇게 넣어줘야만 작동이 되었다. (설치되어있으면 주석만 있으면 작동)
/** @jsxImportSource @emotion/react */
알고보니, CRA는 바벨설정이 불가능하게 세팅되어 있어서
eject를 사용하게 되면 설정이 가능한데 그러면 CRA의 본질 자체를 잃어버리기 때문에 eject는 지양하고 craco를 사용해서 babel preset을 설정하도록 했던 것이다. 참고사이트
그런데 위에 설정대로 해도 주석없이는 적용이 안되고 인라인 css조금만 넣으려다가 많은 설정을 추가해야 되는 상황이라,
그냥 styled로 사용하기로 했다.
( 인라인 CSS를 사용하려면 설치 후 위에 주석을 넣어 사용하고,
그냥 styled로 사용하려면 주석없이도 설치만 되어있으면 사용 가능하다.)
styled 를 통한 컴포넌트 적용 예)
import styled from '@emotion/styled';
const Box = styled.div({
display: 'flex',
justifyContent: 'flex-end',
});
..
return(
<Box />
..
CRA(Create React App) 환경에서 Emotion 설치해서 사용하기
원래는 스타일드 컴포를 가끔 사용하거나 그냥 일반 css파일을 사용하거나 혹은 scss를 사용하여 스타일링을 수정 등 했었습니다만 많은 사람들이 말하는 emotion이 궁금해서 한번 써보기로 결정
okky.tistory.com
https://storycode.tistory.com/419
CRA.babel.webpack.설정
참조 : https://velog.io/@noah071610/CRA%EC%97%90%EC%84%9C-babel%EC%9D%B4%EB%82%98-webpack-%EC%84%A4%EC%A0%95%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95 노아입니다. CRA는 Create react App 의 약자이다 즉 React App 의 초기설정을 쉽게 해주자
storycode.tistory.com
https://www.howdy-mj.me/css/emotionjs-intro
emotion.js 소개 및 사용법 (feat. CSS-in-JS)
업데이트: 2021.05.12 - 주요 내용: @emotion/core 10.0.28 => @emotion/react 11.4.0 업데이트: 2021.05.19 - 주요 내용: Global에서 사용하기, type 설정 ## emotion.js란? emo...
www.howdy-mj.me
CRA + emotion.js 환경에서 jsx pragma 선언 없이 css 사용하기
CRA + emotion.js 환경에서 jsx pragma 없이 사용하기
velog.io
https://junglast.com/blog/react-new-jsx-transform-emotion
React의 새로운 JSX Transform 환경에서 Emotion CSS prop 사용 설정하기
junglast.com
https://simsimjae.tistory.com/410
emotion 사용시 jsx pragma 제거하기
https://medium.com/@harryhedger/quick-how-to-use-the-emotion-css-prop-with-create-react-app-5f6aa0f0c5c5 Quick How-to: Use the emotion `css` prop with create-react-app I’ve heard a few people have had trouble getting emotion’scss prop to work with crea
simsimjae.tistory.com
https://rrecoder.tistory.com/237
@emotion/css error 에러 in React - you have tried to stringify object returned from css function
error message You are loading @emotion/react when it is already loaded. Running multiple instances may cause problems. This can happen if multiple versions are used, or if multiple builds of the same version are used. You have tried to stringify object ret
rrecoder.tistory.com
React 스타일링 - emotion
emotion공식 사이트 : emotion.sh/docs/introduction Emotion - Introduction Emotion is a library designed for writing css styles with JavaScript. It provides powerful and predictable style composition in addition to a great developer experience with feat
wazacs.tistory.com
'React' 카테고리의 다른 글
[React] day.js 사용법 (날짜, 시간 라이브러리) (1) | 2023.03.07 |
---|---|
[React] JS/ 타임스탬프(Date) 날짜 파싱하기(유닉스타임=타임스탬프 를 현재시간으로 변환) (0) | 2023.02.28 |
[React] MUI 모달창 만들기 (0) | 2023.02.23 |
[React] MUI (Material-UI) CSS 사용하기 (0) | 2023.02.21 |
[React] useEffect()의 Callback으로 async 함수를 쓰지 않는 이유 (0) | 2023.02.20 |