Skip to content

Instantly share code, notes, and snippets.

View luillyfe's full-sized avatar
💭
Improving

Fermin Blanco luillyfe

💭
Improving
View GitHub Profile
@luillyfe
luillyfe / App.ts
Last active October 17, 2018 15:26
Angular: props are immutable?
// App Component
export class AppComponent {
title="News title";
content="A description should be here!";
}
// News component
@Component({
selector: 'news',
template: `
@luillyfe
luillyfe / App.ts
Created October 17, 2018 16:27
Angular parent state/ props changed
<news title="{{ title }}" content="{{ content }}"></news>
<button (click)="printState()">Print parent state</button>
/* *** */
export class AppComponent {
title="News title"; s
content="A description should be here!";
printState() {
console.log(`News title: ${this.title}, News content: ${this.content}`);
@luillyfe
luillyfe / Elements.jsx
Created October 19, 2018 20:58
React: Elements
<Body>
<SideBar names={menuNames} />
<Content />
</Body>
@luillyfe
luillyfe / Components.jsx
Last active October 23, 2018 16:38
React Components
<div>
<Menu />
<div>
<Sidebar />
<Content />
</div>
</div>
@luillyfe
luillyfe / Elements.jsx
Created October 23, 2018 16:55
Fillint a child component
<div>
<Sidebar theme="dark" />
<Content text="Lorem Ipsum is simply dummy text of ..." />
</div>
@luillyfe
luillyfe / Stateless.jsx
Last active October 31, 2018 19:23
Stateless Functional Component
import React from "react";
const Menu = props => (
<ul>
{props.options.map(option => <li key={option.id}>{option.name}</li>)}
</ul>
);
import { Component } from "react";
class App extends Component {
constructor(props) {
super(props);
this.state.options = [
{id: 1, name: "home"},
{id: 2, name: "aboutUs"},
{id: 3, name: "contactUs"}
];
class App extends Component {
...
componentDidMount() {
let { options } = this.state.options;
options = options.map(o => {
});
fetch("https://jsonplaceholder.typicode.com/options")
.then(options => JSON.parse(response))
.then(options => (
this.setState({
@luillyfe
luillyfe / app.jsx
Last active November 7, 2018 11:15
React: Props are immutable!
const News = props => {
const changeTitle = () => {
// Since props are read-only, you are not allowed to do so
props.changeTitle("Title changed!");
};
return (
<div>
<h1>{props.title}</h1>
<div>{props.content}</div>
<button onClick={changeTitle}>Mutate!</button>
@luillyfe
luillyfe / App.jsx
Last active November 7, 2018 11:16
React updating props.
const News = props => {
const changeTitle = () => {
props.changeTitle("Title changed!");
};
return (
<div>
<h1>{props.title}</h1>
<div>{props.content}</div>
<button onClick={changeTitle}>Mutate!</button>
</div>