Skip to content

Instantly share code, notes, and snippets.

View biglovisa's full-sized avatar
🌍
Patch is hiring!

Lovisa Svallingson biglovisa

🌍
Patch is hiring!
View GitHub Profile
@biglovisa
biglovisa / state-vs-props.js
Last active December 15, 2015 04:54
react: state vs props
//-------------------------------Main (parent) component
var Main = React.createClass({
// props: name (data)
// state: counter (data)
getInitialState: function() {
return { counter: 0 };
},
handleClick: function() {
this.setState({ counter: ++this.state.counter });
@biglovisa
biglovisa / javascript-recursion.js
Last active December 15, 2015 14:17
JavaScript recursion exercises
// Write a recursive function that outputs the range between two positive numbers
// myFunction(1, 5) #=> [1, 2, 3, 4, 5]
// (5 pts)
// Write a recursive function that outputs the sum of an array of integers
// myFunction([1, 2, 3, 4, 5, 6]) #=> 21
// (5 pts)
@biglovisa
biglovisa / react-notes.md
Created December 16, 2015 16:53
React in theory
@biglovisa
biglovisa / sample.js
Created December 16, 2015 18:50
react sample code
///// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import HelloWorld from './HelloWorld';
ReactDOM.render(<HelloWorld name='Meeka' />, document.getElementById('container'));
///// HelloWorld.js
@biglovisa
biglovisa / old-vs-new.js
Last active December 18, 2015 16:48
Old vs New React class syntax
/// Older
///////////// Here, we specify the defaultProps and the initialState in functions in the component
///////////// We also validate the component props in the propTypes function
var Counter = React.createClass({
getDefaultProps: function(){
return {initialCount: 0};
},
getInitialState: function() {
return {count: this.props.initialCount}