This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormState, FieldState } from 'formstate'; | |
export default class LoginFormState { | |
username = new FieldState('').validators((val) => !val && 'username required'); | |
password = new FieldState('').validators((val) => !val && 'password required'); | |
form = new FormState({ | |
username: this.username, | |
password: this.password | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormState, FieldState } from 'formstate'; | |
export default class LoginFormState { | |
username = new FieldState(''); | |
password = new FieldState(''); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormState, FieldState } from 'formstate'; | |
export default class LoginFormState { | |
username = new FieldState('').validators((val) => !val && 'username required'); | |
password = new FieldState('').validators((val) => !val && 'password required'); | |
form = new FormState({ | |
username: this.username, | |
password: this.password | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import LoginFormState from './formstate'; | |
const LoginForm = () => { | |
const formData = new LoginFormState(); | |
return ( | |
<div className="login-form"> | |
<div className="login-form_field"> | |
<label>username</label> | |
<input onChange={(e) => { formData.username.onChange(e.target.value); }} /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import LoginFormState from './formstate'; | |
import { Observer } from 'mobx-react'; | |
const LoginForm = () => { | |
const formData = new LoginFormState(); | |
return ( | |
<Observer> | |
{() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRef } from 'react'; | |
export const useInstance = <T>(fn: () => T) => { | |
const instanceRef = useRef<T | null>(null); | |
if (instanceRef.current === null) { | |
instanceRef.current = fn(); | |
} | |
return instanceRef.current as T; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import LoginFormState from './formstate'; | |
import { useInstance } from './hooks'; | |
import { Observer } from 'mobx-react'; | |
const LoginForm = () => { | |
const formData = useInstance(() => new LoginFormState()); | |
return ( | |
<Observer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var express_graphql = require('express-graphql'); | |
var { buildSchema } = require('graphql'); | |
// GraphQL schema | |
var schema = buildSchema(` | |
type Query { | |
movie(id: Int!): Movie | |
movies(rate: String): [Movie] | |
}, | |
type Movie { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { Link } from "gatsby" | |
import Layout from "../components/layout" | |
import Image from "../components/image" | |
import SEO from "../components/seo" | |
import { useStaticQuery, graphql } from "gatsby" | |
const IndexPage = () => { | |
const MovieResult = useStaticQuery( | |
graphql` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var { buildSchema } = require('graphql'); | |
var { MoviesList } = require('./movie-list'); | |
var schema = buildSchema(` | |
type Query { | |
movieInfo(id: Int!): Movie | |
movieList(rate: String): [Movie] | |
}, | |
type Movie { | |
id: Int |
OlderNewer