Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Terry Sahaidak terrysahaidak

🎯
Focusing
Block or report user

Report or block terrysahaidak

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@terrysahaidak
terrysahaidak / useAnimatedValue.ts
Created Dec 27, 2019
Hook for reanimated animated value
View useAnimatedValue.ts
export default function useAnimatedValue(
value: number,
listener?: boolean | ((arg: any) => any),
debugLabel?: string,
) {
const lastValue = useRef(null);
const animatedValue = useMemo(() => new Animated.Value(value), []);
useEffect(() => {
@terrysahaidak
terrysahaidak / styled.js
Created Dec 20, 2019
Smallest styled components
View styled.js
function useStyles(styles) {
const [, forceUpdate] = useState();
const [width, height] = useDimensions();
useEffect(() => {
// TODO: debounce it
forceUpdate((v) => v + 1);
}, [width, height]);
View UserStore.js
let UserModel;
const ResolveUser = types
.model('ResolveUser', {
id: types.identifier,
})
.views((self) => ({
get user() {
return resolveIdentifier(UserModel, self, self.id);
},
View setupProxy.js
const createProxy = require('http-proxy-middleware');
const proxy = createProxy({
target: 'https://apiko-marketplace-api-2019.herokuapp.com/',
pathRewrite: {
'^/api': '',
},
changeOrigin: true,
});
@terrysahaidak
terrysahaidak / OnLoad.cpp
Last active Oct 26, 2019
Android JSI OnLoad.cpp with reanimated bindings
View OnLoad.cpp
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#include <fb/fbjni.h>
#include <folly/Memory.h>
#include <jsi/JSCRuntime.h>
#include <jsi/JSIDynamic.h>
#include <jsireact/JSIExecutor.h>
View ScreenInitializerHoc.js
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import { inject } from 'mobx-react';
const RootSpinner = () => <Text>Loading</Text>;
const EmptyCover = ({ retry }) => (
<View>
<Text>Error</Text> <Text onPres={retry}>Retry</Text>
</View>
);
@terrysahaidak
terrysahaidak / mobx-react.js
Created Jul 1, 2019
mobx-react inject/provider with hooks
View mobx-react.js
import React, { useContext, forwardRef } from 'react';
const MSTContext = React.createContext(null);
// eslint-disable-next-line prefer-destructuring
export const Provider = MSTContext.Provider;
export function useMst(mapStateToProps) {
const store = useContext(MSTContext);
View javascript.json
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@terrysahaidak
terrysahaidak / setupProxy.js
Last active May 21, 2019
Proxy for CRA (Apiko courses 2019)
View setupProxy.js
const createProxy = require('http-proxy-middleware');
const proxy = createProxy({
target: 'https://apiko-marketplace-api-2019.herokuapp.com/',
pathRewrite: {
'^/api': '',
},
changeOrigin: true,
});
@terrysahaidak
terrysahaidak / useSuspendedProp.js
Created May 10, 2019
Useful hook to suspend your prop change
View useSuspendedProp.js
export default function useSuspendedProp(prop, timeout = 500) {
const initialValue = useRef(prop);
const [copy, setCopy] = useState(prop);
const timeoutRef = useRef(null);
useEffect(() => {
clearTimeout(timeoutRef.current);
if (
initialValue.current === prop &&
You can’t perform that action at this time.