Code Monkey home page Code Monkey logo

Comments (2)

mdgarden avatar mdgarden commented on June 16, 2024 1

질문 자체가 잘못됐었구나 "훅스를 언제 써야하는가" 가 아니라 훅스를 쓰지 않으면 16.8 이전의 클래스 방식으로 써야만 같은 로직을 구현할 수 있는거였네 🤔

from cs-wiki.

mdgarden avatar mdgarden commented on June 16, 2024

공식문서 요약

  • 훅은 클래스 없이 리액트 기능들을 사용하는 방법을 제시함.
  • 훅은 명령형 코드로 해결책을 찾을 수 있게 해줌

스택오버플로우 답변

  • 리액트 훅스는 16.8에서 소개된 것이다.
  • 클래스를 사용하지 않고 컴포넌트를 작고 재사용하기 쉽게 하기 위한 것.
  • 훅스가 있어서 탑다운 식의 흐름 대신에 컴포넌트 안에서의 흐름을 제어할 수 있게 되었다.
  • 훅스를 사용하면 리액트의 라이프사이클을 이해하지 않아도 된다.
// before hooks
class Example extends React.Component {
  componentDidMount() {
    console.log('I am mounted!');
  }
  render() {
    return null;
  }
}
// after hooks
function Example() {
  useEffect(() => console.log('mounted'), []);
  return null;
}
// before hooks
componentDidMount() {
  console.log('mounted or updated');
}

componentDidUpdate() {
  console.log('mounted or updated');
}
// after hooks
useEffect(() => console.log('mounted or updated'));
  • 훅스를 사용함으로써 더 간결해지고, 재사용성이 높아지는 로직을 짤 수 있다.

from cs-wiki.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.