Skip to content

Instantly share code, notes, and snippets.

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

Sokdara Cheng chengsokdara

🏠
Working from home
View GitHub Profile
@chengsokdara
chengsokdara / useStore.tsx
Created October 15, 2020 01:01
React global state in 15 line of codes, TypeScript version.
// Author: Mr. Cheng Sokdara
import React, {
Dispatch,
FC,
createContext,
useContext,
useReducer,
} from "react";
import initialState, { StoreState } from "./initialState";
@chengsokdara
chengsokdara / useStore.js
Last active June 20, 2024 10:09
React global state in 15 lines of code.
// Author: Sokdara Cheng
// Contact me for web or mobile app development using React or React Native
// https://chengsokdara.github.io
import React, { createContext, useContext, useReducer } from "react";
import initialState from "./initialState"; // object of initial states
import reducer from "./reducer"; // https://reactjs.org/docs/hooks-reference.html#usereducer
const Store = createContext({
dispatch: () => null,
state: initialState,
});
@chengsokdara
chengsokdara / StoraDemo.js
Last active November 11, 2019 16:31
StoRa component sample
import React, { useEffect } from "react";
import useStora from "@rawewhat/stora";
const App = () => {
return (
<div>
StoRa Demo
<TestScreen />
<DemoScreen />
</div>
@chengsokdara
chengsokdara / stora.config.js
Last active November 11, 2019 16:33
StoRa config sample
export default {
// This will be where you initialize your states
states: {
testScreen: {
testState: 'testState'
},
demoScreen: {
demoState: 'demoState'
}
},
@chengsokdara
chengsokdara / telegramBot.js
Created August 9, 2019 00:40
Telegraf Firebase Cloud Function
const functions = require('firebase-functions');
const Telegraf = require('telegraf');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
const bot = new Telegraf(functions.config().bot.token);