인프런 커뮤니티 질문&답변

ryosuke kureha님의 프로필 이미지
ryosuke kureha

작성한 질문수

웹 게임을 만들며 배우는 React

가독성을 위한 JSX(XML임!)

바벨을 적용하니까 에러가 나면서 라이크버튼이 적용되지 않습니다.

작성

·

667

0


element.style
 {
    user agent stylesheet
    body {
    1. display: block;
    margin
    8

    8
    border

    padding

    1113 × 1247


    8

    8
    Default levels
    index.html:95 Live reload enabled.
    react-dom.development.js:11237 Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops. at checkForNestedUpdates (react-dom.development.js:23228) at scheduleUpdateOnFiber (react-dom.development.js:21299) at Object.enqueueSetState (react-dom.development.js:12774) at LikeButton.Component.setState (react.development.js:557) at LikeButton.render (<anonymous>:49:23) at finishClassComponent (react-dom.development.js:17295) at updateClassComponent (react-dom.development.js:17245) at beginWork (react-dom.development.js:18755) at beginWork$1 (react-dom.development.js:23314) at performUnitOfWork (react-dom.development.js:22289)

    답변 3

    0

    제로초 선생님 답변이 보이지 않는데요... ㅠㅠ

    0

    <html>
    <head>
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <!-- <script
    crossorigin
    src="https://unpkg.com/react@17/umd/react.development.js"
    ></script> -->
    <!-- <script crossorigin src="https://unpkg.com/react@16/umd/react.production.js"></script> -->
    <!-- <script
    crossorigin
    src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"
    ></script> -->
    <!-- <script crossorigin src="https://unpkg.com/react-dom@16/umd/react.production.js"></script> -->
    <!-- <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> -->
    </head>
    <body>
    <div id="root"></div>
    <!-- 결과: <div id="root"><button>Like</button></div> -->
    <script type="text/babel">
    // const e = React.createElement; [옛날버전]
    class LikeButton extends React.Component {
    constructor(props) {
    super(props);
    // 바뀔 여지가 있는 부분이 상태(state)입니다. 상태 = state
    this.state = {
    liked: false,
    };
    }

    render() {
    return (
    <button type="submit" onClick={this.setState({ liked: true })}>
    {this.state.liked === true ? "Liked" : "Like"}
    </button>
    );
    // JSX ( JS + XML )

    /** 변경전 [옛날버전]
    e(
    "button",
    {
    onClick: () => {
    this.setState({ liked: true });
    },
    type: "submit",
    },
    this.state.liked === true ? "Liked" : "Like"
    ); **/
    // <button onclick="() => {console.log('clicked')}" type="submit">Like</button>
    // $('button').text('Liked'); 제이쿼리
    }
    }
    </script>
    <script type="text/babel">
    ReactDOM.render(
    <div>
    <LikeButton />
    <LikeButton />
    <LikeButton />
    <LikeButton />
    </div>,
    document.querySelector("#root")
    );
    </script>
    </body>
    </html>

    0

    element.style {
    }
    user agent stylesheet
    body {
        display: block;
        margin: 8px;
    }
    
    Some messages have been moved to the Issues panel.
    View issues
    index.html:95 Live reload enabled.
    babel.min.js:1 You are using the in-browser Babel transformer. Be sure to precompile your scripts for production - https://babeljs.io/docs/setup/
    react-dom.development.js:82 Warning: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.
        in LikeButton
        in div
    react-dom.development.js:19662 The above error occurred in the <LikeButton> component:
        in LikeButton
        in div
    
    Consider adding an error boundary to your tree to customize error handling behavior.
    Visit https://fb.me/react-error-boundaries to learn more about error boundaries.
    react-dom.development.js:11237 Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
        at checkForNestedUpdates (react-dom.development.js:23228)
        at scheduleUpdateOnFiber (react-dom.development.js:21299)
        at Object.enqueueSetState (react-dom.development.js:12774)
        at LikeButton.Component.setState (react.development.js:557)
        at LikeButton.render (<anonymous>:49:23)
        at finishClassComponent (react-dom.development.js:17295)
        at updateClassComponent (react-dom.development.js:17245)
        at beginWork (react-dom.development.js:18755)
        at beginWork$1 (react-dom.development.js:23314)
        at performUnitOfWork (react-dom.development.js:22289)
    
    ​
    
    ryosuke kureha님의 프로필 이미지
    ryosuke kureha

    작성한 질문수

    질문하기