Skip to content

Instantly share code, notes, and snippets.

View riccardogiorato's full-sized avatar
🏠
Working from home

Riccardo Giorato riccardogiorato

🏠
Working from home
View GitHub Profile
import React from 'react';
import useForm from 'react-hook-form';
export default function App() {
const { register, handleSubmit, errors } = useForm();
const onSubmit = data => console.log(data);
console.log(errors);
return (
<form onSubmit={handleSubmit(onSubmit)}>
import React from 'react'
import useForm from 'react-hook-form'
export default function App() {
const { register, handleSubmit, watch, errors } = useForm()
const onSubmit = data => { console.log(data) }
console.log(watch('example')) // watch input value by passing the name of it
return (
import React from 'react'
import useForm from 'react-hook-form'
export default function App() {
const { register, handleSubmit } = useForm()
const onSubmit = data => console.log(data)
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input name="firstName" ref={register({ required: true, maxlength: 20 })} />
import React from 'react'
import useForm from 'react-hook-form'
export default function App() {
const { register, errors } = useForm()
return (
<form onSubmit={handleSubmit(onSubmit)}>
<Input name="firstName" ref={register({ required: true })} />
{errors.firstName && 'First name is required'}
// Current prelude for using `wasm_bindgen`, and this'll get smaller over time!
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
// Here we're importing the `alert` function from the browser, using
// `#[wasm_bindgen]` to generate correct wrappers.
#[wasm_bindgen]
extern {
fn alert(s: &str);
@riccardogiorato
riccardogiorato / main.js
Created October 22, 2019 08:13
rust main JS
const { greet } = wasm_bindgen;
function runApp() {
greet('World');
}
// Load and instantiate the wasm file, and we specify the source of the wasm
// file here. Once the returned promise is resolved we're ready to go and
// use our imports.
wasm_bindgen('../out/main_bg.wasm').then(runApp).catch(console.error);
fn main() {
let _height: u8 = 8;
let _height128: u128 = 1024;
let _float32: f32 = 3.45;
let _thisisfalse: bool = false;
let _char: char = '@';
}
fn main() {
let 42isImmutable = 42;
let mut thisNumberCanBeChanged = 10;
42isImmutable = 84; // ERROR: 42isImmutable is not mutable
thisNumberCanBeChanged = 50;
}