Skip to content

Instantly share code, notes, and snippets.

View eddyw's full-sized avatar
🏠
Working from home

Eddy Wilson eddyw

🏠
Working from home
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@eddyw
eddyw / git-notes.txt
Last active October 31, 2016 01:00
Git Essential Training Course (Git Notes)
Notes:
Git doesn't track empty files.
To keep a directory, create inside it a .gitkeep file with
touch /emptyFolder/.gitkeep
Referencing to commits.
using SHA, or HEAD, HEAD^ (One previous), HEAD^^ (2 back), master^
HEAD points to the very last commit
@eddyw
eddyw / switch.jsx
Last active November 1, 2017 14:39
Suck less at React (utilities #1): Switch Components
<Switch>
<Route exact path="/section1" component={Section1} />
<Route exact path="/section2" component={Section2} />
<Route exact path="/section3" component={Section3} />
<Route component={NotFound} />
</Switch>
@eddyw
eddyw / ugly-code.jsx
Created November 1, 2017 14:41
Suck less at React (utilities #1): Switch Components
<section>
{
this.props.section === 1
? <Section1 /> :
this.props.section === 2
? <Section2 />
this.props.section === 3
? <Section3 />
: null
}
@eddyw
eddyw / second-ugly-code.js
Created November 1, 2017 14:42
Suck less at React (utilities #1): Switch Components
<section>
{
this.props.section === 1 &&
this.props.isUserLogged
? <SectionUserLogged /> :
this.props.section === 1
? <SectionUserNotLogged />
this.props.section === 2 &&
this.props.isUserLogged &&
this.props.isUserAdmin
@eddyw
eddyw / SwitchIf.jsx
Last active November 1, 2017 14:46
Suck less at React (utilities #1): Switch Components
import React from 'react'
import propTypes from 'prop-types'
import SwitchWhen from './SwitchWhen'
class SwitchIf extends React.PureComponent {
static propTypes = {
test: propTypes.any.isRequired,
equals: propTypes.any,
children: props => (
React.Children
@eddyw
eddyw / simple-conditions.jsx
Created November 1, 2017 14:48
Suck less at React (utilities #1): Switch Components
<section>
<SwitchIf test={this.props.section}>
<SwitchWhen equals={1} render={<Section1 />} />
<SwitchWhen equals={2} render={<Section2 />} />
<SwitchWhen equals={3} render={<Section3 />} />
</SwitchIf>
</section>
@eddyw
eddyw / complex-conditions.jsx
Created November 1, 2017 14:49
Suck less at React (utilities #1): Switch Components
<section>
<SwitchIf test={this.props.section}>
<SwitchIf equals={1} test={this.props.isUserLogged}>
<SwitchWhen equals={true} render={<SectionUserLogged />} />
<SwitchWhen equals={false} render={<SectionUserNotLogged />} />
</SwitchIf>
<SwitchIf equals={2} test={this.props.isUserAdmin}>
<SwitchWhen equals={true} render={<SectionDashboard />} />
</SwitchIf>
<SwitchWhen equals={3} render={<SectionAbout />} />
@eddyw
eddyw / form-component-example.jsx
Last active November 1, 2017 16:44
Suck Less at React: Understanding refs
import React from 'react'
import propTypes from 'prop-types'
import { render } from 'react-dom'
class Form extends React.Component {
static propTypes = {
onSubmit: propTypes.func.isRequired,
}
render() {
return (
@eddyw
eddyw / instance-refs.jsx
Created November 1, 2017 16:47
Suck Less at React: Understanding refs
import React from 'react'
import propTypes from 'prop-types'
import { render } from 'react-dom'
class Form extends React.Component {
static propTypes = {
onSubmit: propTypes.func.isRequired,
}
constructor(...rest) {
super(...rest)