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 / examples.ts
Last active May 28, 2024 17:41
Children handling with React FC
const NoChildrenAllowed: ReactFC<NoChildren> = () => null
const RequireSingleChild: ReactFC<Required<SingleChild>> = () => null
type TProps = Required<SomeChildren> & {
otherProp: number
}
const RequireMoreChildrenAndOtherProps: ReactFC<TProps> = () => null
@danielkcz
danielkcz / formik-mobx.js
Last active July 26, 2023 21:51
Formik with MobX
function useFormik(props) {
// useState to keep the same observable around without recreating it on each render
const [formik] = React.useState(() =>
mobx.observable({
values: props.initialValues || {},
touched: {}
})
)
// just mutate state, this function itself can be considered an action+reducer
@danielkcz
danielkcz / App.js
Created September 6, 2017 12:59
Update Expo app
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Util } from 'expo'
export default class App extends React.Component {
state = {
updated: false,
}
componentWillMount() {
Util.addNewVersionListenerExperimental(() => {
@danielkcz
danielkcz / RandomGiphy.jsx
Last active October 15, 2020 05:19
useQuery + useContext
import { useQuery } from 'react-apollo-hooks'
const RandomGiphy = () => {
const { tag } = useSettings()
const { data } = useQuery(
RandomGiphyQuery, {
variables: { tag }
}
}
// handle loading & error states...
export type TEventTriggerPayload<TData> = {
event: (
| TEvent<'INSERT', null, TData>
| TEvent<'UPDATE', TData, TData>
| TEvent<'DELETE', TData, null>
| TEvent<'MANUAL', null, TData>
) & {
session_variables: Dictionary
}
created_at: ISODateTime
@danielkcz
danielkcz / machine.js
Created March 14, 2020 17:05
Generated by XState Viz: https://xstate.js.org/viz
const audioStreamMachine = Machine({
id: 'audioStream',
initial: 'idle',
context: {
stream: null,
streamError: null,
},
states: {
idle: {
on: {
@danielkcz
danielkcz / machine.js
Last active January 6, 2020 18:20
Generated by XState Viz: https://xstate.js.org/viz
const tickEvent = (gear) => ({ type: 'TICK', gear })
const trainMachine = Machine(
{
id: 'train',
initial: 'inactive',
context: {
position: {
x: 0,
y: 0,
@danielkcz
danielkcz / mobx.js
Last active December 27, 2019 09:11
Formik with MobX #2
React.useEffect(() =>
mobx.autorun(() => {
if (props.validate) {
// MobX will see use of formik.values and rerun this function whenever it is mutated
formik.errors = props.validate(formik.values);
}
}), []
);
@danielkcz
danielkcz / machine.js
Last active November 16, 2019 22:32
Generated by XState Viz: https://xstate.js.org/viz
const reset = assign({
value: ({ initialValue }) => initialValue
})
const updateValue = assign({
value: (_, ev) => ev.value
})
const isEnterOrTab = (_, ev) => ['Enter', 'Tab'].includes(ev.key)
@danielkcz
danielkcz / machine.js
Created November 12, 2019 20:10
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)