This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h1>Hi, {this.props.name}</h1> | |
</div> | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyComponent = ({name}) => ( | |
<div> | |
<h1>Hi, {name}</h1> | |
</div> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { TextField, Button, Grid } from "@material-ui/core"; | |
import axios from 'axios'; | |
class SignupForm extends React.Component { | |
state = { | |
email: "", | |
emailError: "", | |
password: "", | |
passwordError: "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const withLocalStorage = (WrappedComponent) => { | |
const loadFromStorage = (key) => localStorage.getItem(key); | |
const saveToStorage = (key, value) => localStorage.setItem(key, value); | |
const removeFromStorage = (key) => localStorage.removeItem(key); | |
return (props) => ( | |
<WrappedComponent | |
loadFromStorage={loadFromStorage} | |
saveToStorage={saveToStorage} | |
removeFromStorage={removeFromStorage} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withStateHandlers, compose } from "recompose"; | |
const initialState = { | |
email: { value: "" }, | |
password: { value: "" }, | |
confirmPassword: { value: "" } | |
}; | |
const onChangeEmail = props => event => ({ | |
email: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withProps } from "recompose"; | |
const getEmailError = email => { | |
if (!email.isDirty) { | |
return ""; | |
} | |
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
const isValidEmail = emailRegex.test(email.value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withProps } from "recompose"; | |
const getPasswordError = password => { | |
if (!password.isDirty) { | |
return ""; | |
} | |
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/; | |
const isValidPassword = passwordRegex.test(password.value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withProps } from "recompose"; | |
const getConfirmPasswordError = (password, confirmPassword) => { | |
if (!confirmPassword.isDirty) { | |
return ""; | |
} | |
const passwordsMatch = password.value === confirmPassword.value; | |
return !passwordsMatch ? "Passwords don't match." : ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withHandlers } from "recompose"; | |
import axios from "axios"; | |
const handleSubmit = ({ | |
email, | |
password, | |
emailError, | |
passwordError, | |
confirmPasswordError | |
}) => { |
OlderNewer