Skip to content

Instantly share code, notes, and snippets.

View Siemko's full-sized avatar
🐐
🐐 🐙 :octocat:

Dominik Guzy Siemko

🐐
🐐 🐙 :octocat:
View GitHub Profile
@Siemko
Siemko / FormSample.vue
Last active February 3, 2018 15:56
Field definition in Vue.js
<template>
<div class="field">
<label class="label">Employer</label>
<div class="control">
<input class="input" type="text" v-model="employer" />
</div>
</div>
</template>
@Siemko
Siemko / Counter.jsx
Last active July 8, 2021 08:24
Counter component in React.js
import React, { Component } from "react";
export default class Counter extends Component {
state = {
title: "Counter",
counter: 0
};
incrementCounter = () => {
this.setState(prevState => ({
@Siemko
Siemko / sample.vue
Last active February 3, 2018 15:49
Sample Vue single file component
<template>
<h1>{{ greeting }} world!</h1>
</template>
<script>
export default {
data () {
return {
greeting: 'Hello'
}
class WorkerInfo extends React.Component {
state = { worker: null }
componentDidMount() {
// Simulate fetching data:
setTimeout(() => this.setState({
worker: `Hi, I am ${this.props.name} and I am proud to work for ${this.props.employer}`
}), 2500);
}
render() {
return this.props.children(this.state.worker);
const Worker = props => <p>{props.message}</p>
const Loading = () => <p>Loading...</p>
const Connect = ComposedComponent =>
class extends React.Component {
state = { name: "" }
componentDidMount() {
//fetching data is a part of HOC
getAsync('https://imaginary-api.gorrion.io/name')
.then(({ name }) => { this.setState({ name: name }) })
}
const Greeting = ({ name, ...props }) => {
if (!name) {
return <div>Loading...</div>
}
return <div {...props}>Hi {name}!</div>
}
class CommentListContainer extends React.Component {
state = { comments: [] }
componentDidMount() {
getAsync("https://imaginary-api.gorrion.io/my-comments")
.then(comments => this.setState({ comments }))
}
render() {
return <CommentList comments={this.state.comments} />;
}
const Commentlist = ({comments}) => (
<ul>
{comments.map(({ body, author }) =>
<li>{body}-{author}</li>
)}
</ul>
)