Skip to content

Instantly share code, notes, and snippets.

@xyzdata
Created June 23, 2017 01:32
Show Gist options
  • Save xyzdata/0080e188a6921504717220fdae5eddb9 to your computer and use it in GitHub Desktop.
Save xyzdata/0080e188a6921504717220fdae5eddb9 to your computer and use it in GitHub Desktop.
ant-design & react click bug!

ant-design & react click bug!

ant-design/ant-design#6576

prevent-react-component-click-event-bubble-to-document

https://stackoverflow.com/questions/44711549/how-to-prevent-react-component-click-event-bubble-to-document

    
//todo


Dynamically add child components in React

https://stackoverflow.com/questions/36651583/dynamically-add-child-components-in-react

    
var App = React.createClass({

    getInitialState: function(){
        return [
            {id:1,name:"Some Name"}
        ]
    },

    addChild: function() {
        // State change will cause component re-render
        this.setState(this.state.concat([
            {id:2,name:"Another Name"}
        ]))
    }

    render: function() {
        return (
            <div>
                <h1>App main component! </h1>
                <button onClick={this.addChild}>Add component</button>
                {
                    this.state.map((item) => (
                        <SampleComponent key={item.id} name={item.name}/>
                    ))
                }
            </div>
        );
    }

});

<Component {...this.props} more="values" />

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

new window url
window location

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

function formatDate(date) {
  return date.toLocaleDateString();
}

function PropsTest(props) {
  return (
    <div>
      <h1>just props test!</h1>
      <span>My name is {props.name}</span>
      <h1>Age:{props.age}</h1>
    </div>
  );
}

function Comment(props) {
  return (
    <div className="Comment">
      <div className="UserInfo">
        <img className="Avatar"
             src={props.author.avatarUrl}
             alt={props.author.name} />
        <div className="UserInfo-name">
          {props.author.name}
        </div>
      </div>
      <div className="Comment-text">
        {props.text}
      </div>
      <div className="Comment-date">
        {formatDate(props.date)}
      </div>
      <hr />
      <PropsTest {...infos}/>
    </div>
  );
}

const infos = {
  name: 'xgqfrms',
  age: 23
};
const comment = {
  date: new Date(),
  text: 'I hope you enjoy learning React!',
  author: {
    name: 'Hello Kitty',
    avatarUrl: 'http://placekitten.com/72/72'
  }
};
ReactDOM.render(
  {/* es6 destructuring assignment*/}
  <div>
    <Comment {...comment} />
    <PropsTest {...infos}/>
  </div>,
  document.getElementById('root')
);

https://codepen.io/anon/pen/xrLRZp?editors=0010

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

A GIF is worth a thousand words:

https://facebook.github.io/react/blog/

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

https://webpack.js.org/guides/migrating/#code-splitting-with-es2015

https://webpack.js.org/guides/code-splitting-async

function onClick() {
  import("./module").then(module => {
    return module.default;
  }).catch(err => {
    console.log("Chunk loading failed");
  });
}

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

function formatDate(date) {
  return date.toLocaleDateString();
}

function PropsTest(props) {
  return (
    <div>
      <h1>just props test!</h1>
      <span>My name is {props.name}</span>
      <h1>Age:{props.age}</h1>
    </div>
  );
}

function Comment(props) {
  return (
    <div className="Comment">
      <div className="UserInfo">
        <img className="Avatar"
             src={props.author.avatarUrl}
             alt={props.author.name} />
        <div className="UserInfo-name">
          {props.author.name}
        </div>
      </div>
      <div className="Comment-text">
        {props.text}
      </div>
      <div className="Comment-date">
        {formatDate(props.date)}
      </div>
      <hr />
      <PropsTest {...infos}/>
    </div>
  );
}

const infos = {
  name: 'xgqfrms',
  age: '23'
};

const comment = {
  date: new Date(),
  text: 'I hope you enjoy learning React!',
  author: {
    name: 'Hello Kitty',
    avatarUrl: 'http://placekitten.com/72/72'
  }
};
ReactDOM.render(
  <div>
     <Comment {...comment} />
     <PropsTest {...infos}/>
  </div>,
  document.getElementById('root')
);

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

@xyzdata
Copy link
Author

xyzdata commented Jun 23, 2017

json-server

$ npm install -g json-server



https://github.com/typicode/json-server



$ json-server --watch db.json



json-server --watch data.json --port 8888


http://localhost:8888/


@xgqfrms-GitHub
Copy link

xgqfrms-GitHub commented Jun 23, 2017

http://editorconfig.org/

# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 4

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 4

@xgqfrms-GitHub
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment