Skip to content

Instantly share code, notes, and snippets.

View danielkcz's full-sized avatar
🏗️
Building own experimental dating app

Daniel K. danielkcz

🏗️
Building own experimental dating app
View GitHub Profile
@danielkcz
danielkcz / machine.js
Created November 12, 2019 18:41
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@danielkcz
danielkcz / machine.js
Last active November 12, 2019 17:29
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@danielkcz
danielkcz / RandomGiphy.jsx
Last active February 19, 2019 18:42
useQuery reusable
import { observer } from 'mobx-react-lite'
const RandomGiphy = observer(() => {
const settings = useSettings()
const giphy = useRandomGiphy(settings.tag)
return giphy ? <img src={giphy.url} /> : null
})
@danielkcz
danielkcz / mutations.jsx
Last active February 15, 2019 07:58
Mutations with Hooks
// HOC approach was first and some still prefer it for whatever reasons
// Along with recompose you can do some real nasty tricks
const MutateMe = graphql(MutationDocument, { name: 'execute' })(({ execute }) => {
// In comparison it's not a terrible way to execute a mutation
// But naming the mutation with string 😆
return <button onClick={() => execute({ variables: { secretName: 'Me' }})} />
})
// Mutation component is fine for simple cases, but gets ugly otherwise
const MutateMe = () => {
@danielkcz
danielkcz / SettingsProvider.jsx
Last active February 14, 2019 20:49
useQuery with MobX
import React from 'react'
const context = React.createContext(mobx.observable({
tag: 'kittens'
}))
export const SettingsProvider = ({ children }) => {
// we can employ some persistence here and load previous settings
// for now just return children because context already has state set
return children
import { useQuery } from 'react-apollo-hooks'
const RandomGiphy = ({ tag }) => {
const { data } = useQuery(
RandomGiphyQuery, {
variables: { tag }
}
}
// handle loading & error states...
return <img src={data.giphy.random.url} />
@danielkcz
danielkcz / formik-state.js
Last active February 13, 2019 13:36
Formik with MobX #3
const formik = mobx.observable({
values: props.initialValues || {},
touched: {},
errors: {},
// scalar values needs to be wrapped into another object
// otherwise after spreading MobX would lost track of it
state: {
isSubmitting: false,
submitError: null
}
@danielkcz
danielkcz / mobx-react-form.d.ts
Created March 1, 2018 08:49
Crude typescript defintion for MRF
declare module 'mobx-react-form' {
export default MRF.MobxReactForm
}
type Dictionary<T> = { [key: string]: T }
declare namespace MRF {
class MobxReactForm {
constructor(options: MRF.Options, settings?: MRF.Settings)
isValid: boolean
@danielkcz
danielkcz / firebase.functions.js
Last active January 11, 2019 12:40
Firebase authentication with Graphcool
const functions = require('firebase-functions')
const admin = require('firebase-admin')
// This is hosted using Firebase Functions to gain easier access without meddling with service key
admin.initializeApp(functions.config().firebase)
exports.verifyToken = functions.https.onRequest((req, res) => {
const { idToken } = req.query
if (!idToken) {
import { Trans } from '@lingui/react'
import React, { Children } from 'react'
interface IProps {
children: ReactNode | string
}
interface IState {
refs: React.RefObject<Trans>[]