Skip to content

Instantly share code, notes, and snippets.

View jlittlejohn's full-sized avatar

Josh Littlejohn jlittlejohn

View GitHub Profile
@jlittlejohn
jlittlejohn / Button.tsx
Created May 3, 2019 01:19
REACT: Class Component with Constructor - TypeScript
export interface ButtonProps {
label?: string;
}
export interface ButtonState {
//
}
class Button extends React.Component<ButtonProps, ButtonState> {
constructor(props: ButtonProps) {
@jlittlejohn
jlittlejohn / Button.tsx
Last active May 3, 2019 13:34
REACT: Basic Stateless Functional Component - TypeScript
export interface ButtonProps {
label?: string;
}
const Button: React.FunctionComponent<ButtonProps> = props => {
return <button>{props.label}</button>;
};
export default Button;
@jlittlejohn
jlittlejohn / ajax.js
Last active May 2, 2019 04:46
REACT: API Call Example
constructor(props) {
super(props);
this.state = {
items: []
};
}
componentDidMount() {
fetch("http://example.com/api/endpoint/")
//fetch("https://cors.io/?http://example.com/api/endpoint/")
@jlittlejohn
jlittlejohn / basic-form.js
Last active May 2, 2019 03:56
REACT: Basic Form Component Example
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ""
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
@jlittlejohn
jlittlejohn / example.js
Last active May 2, 2019 02:12
REACT: State Change onClick Example
class SomeComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
value: 1
};
}
handleButtonChange() {
this.setState({
@jlittlejohn
jlittlejohn / example2.js
Created May 1, 2019 19:03
REACT: Render an Array of Objects in a Class Component
var users = [
{ id: 1, name: "Chris" },
{ id: 2, name: "Jeff" },
{ id: 3, name: "Julie" },
{ id: 4, name: "Jessica" }
];
class UserList extends React.Component {
render() {
var users = this.props.users;
@jlittlejohn
jlittlejohn / example2.js
Created May 1, 2019 18:59
REACT: Render an Array of Objects in Stateless Functional Component
var users = [
{ id: 1, name: "Chris" },
{ id: 2, name: "Jeff" },
{ id: 3, name: "Julie" },
{ id: 4, name: "Jessica" }
];
function UserList(props) {
var users = props.users;
var usersListItems = users.map(function(user) {
@jlittlejohn
jlittlejohn / example2.js
Created May 1, 2019 17:14
JS: Array Map Method Example
var forecast = [
{ day: "Monday", sun: true, humidity: 10 },
{ day: "Tuesday", sun: false, humidity: 100 },
{ day: "Wednesday", sun: false, humidity: 100 },
{ day: "Thursday", sun: true, humidity: 25 },
{ day: "Friday", sun: false, humidity: 100 },
{ day: "Saturday", sun: true, humidity: 15 },
{ day: "Sunday", sun: false, humidity: 100 }
];
@jlittlejohn
jlittlejohn / example2.js
Created May 1, 2019 16:53
JS: Do / While Loop Example
do {
text += "The number is " + i;
i++;
}
while (i < 10);
@jlittlejohn
jlittlejohn / example2.js
Created May 1, 2019 16:53
JS: While Loop Example
while (i < 10) {
text += "The number is " + i;
i++;
}