Git Product home page Git Product logo

react-style-guide's Introduction

شیوه‌نامه‌ی React/JSX از Airbnb

(Persian Translation of Airbnb React/JSX Style Guide)

یک رویکرد معقول برای React and JSX

این شیوه‌نامه مبتنی بر استانداردهای موجود در جاوااسکریپت است، هرچند ممکن است برخی از قراردادها (مانند async/await یا فیلدهای استاتیک در کلاس) به صورت موردی قابل قبول یا ممنوع باشند. در حال حاضر هر چیزی قبل از مرحله 3 در این راهنما توصیه نمی شود.

فهرست مندرجات

  1. قوانین اساسی
  2. تفاوت Class، React.createClass و stateless
  3. Mixinها
  4. نام‌گذاری
  5. تعریف
  6. ترازبندی
  7. Quotes
  8. فاصله‌گذاری
  9. Propها
  10. Refها
  11. پرانتزها
  12. تگ‌ها
  13. توابع
  14. مرتب‌ سازی
  15. isMounted

قوانین اساسی

  • در هر فایل یک کامپوننت ری‌اکت داشته باشید.
  • همیشه از سینتکس JSX استفاده کنید.
  • هیچ‌وقت از React.createElement استفاده نکنید مگر آنکه برنامه را از فایلی شروع می‌کنید که JSX نیست.

تفاوت Class، React.createClass و stateless

  • درحالتی که state یا ref یا هر دو را دارید، class extends React.Component بهتر از React.createClass است. eslint: react/prefer-es6-class react/prefer-stateless-function

    // بد
    const Listing = React.createClass({
      // ...
      render() {
        return <div>{this.state.hello}</div>;
      }
    });
    
    // خوب
    class Listing extends React.Component {
      // ...
      render() {
        return <div>{this.state.hello}</div>;
      }
    }

    و اگر state یا ref ندارید، تابع عادی (نه arrow functions) بهتر از کلاس است:

    // بد
    class Listing extends React.Component {
      render() {
        return <div>{this.props.hello}</div>;
      }
    }
    
    // بد (متکی بودن به استنتاج اسم تابع توصیه نمی‌شود) 
    const Listing = ({ hello }) => (
      <div>{hello}</div>
    );
    
    // خوب
    function Listing({ hello }) {
      return <div>{hello}</div>;
    }

Mixinها

چرا؟ mixinها وابستگی ضمنی ایجاد می‌کنند، باعث تلاقی اسم‌ها و پیچیدگی گلوله برفی (؟) می‌شن. بیشتر موارد استفاده از mixinها را می‌شود با روش‌های بهتری از طریق کامپونتت‌ها، higher-order کامپوننت‌ها یا ماژول‌های utility انجام داد.

نام‌گذاری

react-style-guide's People

Contributors

mehrnooshdsht avatar

Watchers

 avatar  avatar

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.