Skip to content

Instantly share code, notes, and snippets.

View gaperton's full-sized avatar

Vlad Balin gaperton

View GitHub Profile
// Minimal working example demonstrating the two-way data binding with React Hook.
import React, { useState } from 'react'
export const MyCoolComponent = () => {
const [ name, setName ] = useState( '' );
return (
<input value={ name }
onChange={ e => setName( e.target.value ) }
/>
// Minimal working example demonstrating the two-way data binding with React Hook.
import { useLink } from 'valuelink'
import * as React from 'react'
export const MyCoolComponent = () => {
const name = useLink( '' );
return (
<input {...name.props} />
)
@gaperton
gaperton / basic.js
Last active April 23, 2019 21:41
Reach Hooks into NestedLink
import React from 'react';
import { useLink } from 'valuelink'
function Example() {
const counter = useLink(0);
return (
<div>
<p>You clicked {counter.value} times</p>
<button onClick={counter.action( x => x + 1 )}>
@gaperton
gaperton / afterRender.js
Last active December 2, 2018 03:20
afterRender( hook )
const AfterRenderMixin = {
componentDidMount : callAfterRenderHooks,
componentDidUpdate : callAfterRenderHooks,
afterRender( hook ){
const { _callAfterRender } = this;
this._callafterRender = _callAfterRender ? () => {
_callAfterRender();
hook();
} : hook;
@gaperton
gaperton / models.js
Last active March 8, 2018 23:19
mobx serializer example with Type-R
import { define, Record } from 'type-r';
@define
export class Box extends Record {
static attributes = {
x : Number,
y : Number,
location : String
}
@define class UserForm extends React.Component {
static state = {
name : '',
email : '',
isActive : true
}
onSubmit = () => { /* TBD */ };
onCancel = () => { /* TBD */ };