Code Monkey home page Code Monkey logo

react-bits's Introduction

react-bits's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-bits's Issues

React Loadable

(Shameless plug)

I wrote this library react-loadable to standardize the workflow around code-splitting at the component-level and asynchronously loading components. I wrote a blog post too.

Facebook does code-splitting this way too.

I think we should be encouraging more of the community to do this since I've heard of people dropping 100s of KBs from their bundles. It's really more a pattern than a library anyways.

List components

https://vasanthk.gitbooks.io/react-bits/patterns/32.list-components.html

I suggest putting that list item mapping function above SearchSuggestions component definition like below:

const renderSearchSuggestion = listItem => (
  <li key={listItem.id}>{listItem.name} {listItem.id}</li>
);

const SearchSuggestions = (props) => {
  return (
    <ul>
      {props.listItems.map(renderSearchSuggestion)}
    </ul>
  );
};

That way we do not create a new function each time SearchSuggestions rerenders.

Misleading Anti-Patterns

In my understanding, titles of Refs over findDomNode() and HOC over mixins in anti-patterns are actually preferred patterns. These two titles looks so weird in Anti-Patterns sections.

It must be titled as findDomNode over Refs and mixins over HOC to be anti-patterns and consistent with other parts.

Gitbook

it would be awesome if this was made with gitbook, easey to ready/navigate... is there any possibility to make this a gitbook doc?

Possible typo in 18.conditionals-in-jsx.md under "do expression" section

From reading about do expressions, it seems that the code section under the text

With an appropiate transpiler you can take advantage of the upcoming do expression which is currently on stage-1

should be do { instead of do => { on line 5, but I'm not 100% sure. Can someone please clarify?

`domProps` props on DOM elements

According to Spreading props on DOM elements, it is recommended to use a domProps object to spread props on DOM elements.

GOOD

By creating props specifically for DOM attribute, we can safely spread.

const Sample = () => (<Spread flag={true} domProps={{className: "content"}}/>);
const Spread = (props) => (<div {...props.domProps}>Test</div>);

But directly passes domProps prop may cause unnecessary update in PureComponent.

Here is an example

import React, { Component, PureComponent } from 'react';
import { render } from 'react-dom';

class Spread extends PureComponent {
  componentDidUpdate() {
    console.log('updated'); // will show
  }

  render() {
    return (
      <div {...this.props.domProps}>Test</div>
    );
  }
}

class App extends Component {
  componentDidMount() {
    this.forceUpdate();
  }

  render() {
    return (
      <Spread flag={true} domProps={{ className: 'content' }}/>
    );
  }
}

render(<App />, document.getElementById('mount'));

Here is my solution by omitting unknown HTML props

import React, { Component, PureComponent } from 'react';
import { render } from 'react-dom';

class Spread extends PureComponent {
  componentDidUpdate() {
    console.log('updated'); // will NOT show
  }

  render() {
    const {
      flag, // eslint-disable-line
      ...other,
    } = this.props;
    return (
      <div {...other}>Test</div>
    );
  }
}

class App extends Component {
  componentDidMount() {
    this.forceUpdate();
  }

  render() {
    return (
      <Spread flag={true} className="content"/>
    );
  }
}

render(<App />, document.getElementById('mount'));

Another solution is caching domProps object, but I think both of my solutions are not elegant 😂

Incorrect explanation in Layout container example

Hi! First of all wanted to say thank you for contributing such an great set of resources and information about React stuff. Awesome job!

Still haven't finished reading all of the content in the repo, but when I read the example in https://github.com/vasanthk/react-bits/blob/master/13.layout-container.jsx, I found some incorrect information regarding the optimization that can be made there.

It says:

// While HorizontalSplit will be parent to both components, it will never be their owner.
// We can tell it to update never, without interrupting the lifecycle of the components inside.

This in fact won't work as it is explained there. The reconciliation in React does not depend on the elements being owners or not. If the HorizontalSplit component doesn't render, its content won't update either, it doesn't matter if the elements were received via props or created by the component directly.

You can try that in this fiddle I created: https://jsfiddle.net/69z2wepo/74765/

I don't think there's a good way to tell React that a component is static and avoid its reconciliation. At least not a straight forward way.

Maybe that pattern should not talk about perf improvements and only about splitting layout vs content components, which is a good idea by itself anyway?

Name for props of component prop use?

I'm starting to use a pattern like this frequently. The reason being there are multiple date-pickers in Scheduler and if you use a component instead of just another object of props you get code completion, etc. and the consuming engineer doesn't need to go look the prop up on the doc site.

Maybe it's a type of HOC pattern, because typically the Datepicker component just gets discarded by Scheduler and the props are stolen. Any naming suggestions?

"Grandfather steals from grandprops" doesn't fly off the tongue that easily. 😄

<Scheduler
  datepickerSharedProps={<Datepicker
    assistiveText={{
      openCalendar: 'Open Calendar',
      nextMonth: 'Next month',
      previousMonth: 'Previous month'
    }}
    formatter={(date) => {
      let inputText = '';
      /* Make American or the Entire Rest of the World format here. */
      if (date) {
        inputText = `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
      }
      return inputText;
    }}
  />}
/>

Maybe Child Component Proxy?

Linter

I just read a few examples, but many of them look a bit too esoteric, and for instance they don't pass a "standard" linter (e.g. the classic eslint+airbnb). One for all, nesting ternary operators.

I think in general this could improve a ton if the "wrong examples" wouldn't be abstract, but concrete/real world enough, and in general not things that a linter would catch already. (Not trying to be overly critic, love this kind of works.)

“Conventions” reflect neither community conventions nor React team recommendations

Hey! Thanks for your work on creating learning material in this repo.

I think the list of “conventions” is highly subjective right now. The React team never advocated any of them, and in fact I think the team would disagree with some:

It would be great to separate author’s stylistic preferences from correctness advice (e.g. about tbody) and clearly label it as such. Those are not React community’s conventions, nor are they recommended by React team.

Best practices for role-based UI

Its fantastic list so far, i have being following it very closely. However, recently i have being struck with role-based implementation in react. Any thoughts on this you came across?

Remove plagiarized content

This is a dupe of #21.

The issue is not resolved. The delay was on account of my father passing away. Obviously this is a decidedly less important issue. However, I will do my best to file the appropriate paperwork this week.

This issue of plagiarism for this repo and all forks remains an open issue.

Some confusions on the anti-patterns

Hey,

I feel we should add more clarity on the anti pattern bits.
For instance, in the refs over findDOMNode(), in the code comments, it's saying: Use findDOMNode() over callback refs which is kind of stating you should use findDOMNode over refs, although after reading the references, it's clearly the opposite we should do.

Although on the HOC over Mixins example (and that's where I think there is some confusion), it's saying Use Higher order components over Mixins, which this time is the right approach.

How do you feel about choosing one or the other approach but staying consistent? I'd suggest saying something like Use "this" over "that" kind of structure.

Extend event handlers with an example of arrow function in class property

Based on the description. If project owners are ok enable Stage 2 Babel transformation it is a good alternative to bind in the constructor.

class Switcher extends React.Component {
  constructor(props) {
    super(props);
    this.state = { name: 'React in patterns' };
  }
  render() {
    return (
      <button onClick={ this.onButtonClick }>
        click me
      </button>
    );
  }
  onButtonClick = () => {
    console.log(`Button is clicked inside ${ this.state.name }`);
  }
}

Let me know if you accept the PR.

Why can’t use regular if/else conditions inside a component definition?

In Section Conditional Rendering, It says:

You can’t use regular if/else conditions inside a component definition. The conditional (ternary) operator is your friend.

I think it is wrong. Because instead of

// if- else (big blocks)
function render() {
  return condition ? (
    <span>
    Rendered when `truthy`
  </span>
  ) : (
    <span>
    Rendered when `falsey`
  </span>
  )
}

this render function can also be written in a if/else way:

function render() {
  if (condition) {
    return  (
      <span>
        Rendered when `truthy`
      </span>
    )
  }
  else {
    return  (
      <span>
        Rendered when `falsey`
      </span>
    )
  }
}

Typescript branch

I think there's enough interest in Typescript to maybe copy this over and redo in TS and TSX files.

Not issues~

i'm too lazy to PR

Here is my tips

modify the tagname according to the parameter

    const Wrap = ({ tagName, content }) => { 
      const Tag = `${tagName}`     // variable name must begin with capital letters
      return <Tag>{content}</Tag>
    }

[Using Indexes as Key] Misleading information

Anti-patterns' Using Indexes as key section is based on an outdated article and is no longer correct.

Keys should be stable, predictable, and unique. Unstable keys (like those produced by Math.random()) will cause many component instances and DOM nodes to be unnecessarily recreated, which can cause performance degradation and lost state in child components.

A more entertaining explanation can be found here (credit to Lin Clark).

Suggestions:

  • replace the blog link with a link to the React docs
  • remove the "Even Better" section
  • rename the "Better" section title to "Good"
  • add an explanation how obj.id should be unique and repeatable among all siblings

@vasanthk I'm happy to open a PR for this, if you are satisfied with the suggestions I made 👍

Remove plagiarized content

Many of the items are plagiarised from reactpatterns.com, which is not licensed.

The content on reactpatterns.com is not licensed. Making this content a copyright violation.

Please let me know that you received this issue and we'll work toward an immicable solution.

As a trainer I take these violations very seriously.

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.