Skip to content

Instantly share code, notes, and snippets.

View CaptainN's full-sized avatar

Kevin Newman CaptainN

View GitHub Profile
@CaptainN
CaptainN / App.js
Created June 17, 2020 00:54
React Native Example App.js
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, TextInput, Button, FlatList, Image } from 'react-native';
import { AsyncStorage } from 'react-native';
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
@CaptainN
CaptainN / App.js
Last active June 10, 2020 00:45
React Native Workshop
import React, { useState } from 'react';
import { StyleSheet, Text, View, Button, FlatList, CheckBox } from 'react-native';
/**
* A computer language has 3 main parts:
* 1. Syntax
* 2. A Static environment
* 3. A Dynamic environment
*
* The syntax the format of the input. The struction of the
@CaptainN
CaptainN / App.js
Created June 10, 2020 00:42
React Native Workshop
import React, { useState } from 'react';
import { StyleSheet, Text, View, Button, FlatList, CheckBox } from 'react-native';
/**
* A computer language has 3 main parts:
* 1. Syntax
* 2. A Static environment
* 3. A Dynamic environment
*
* The syntax the format of the input. The struction of the
@CaptainN
CaptainN / Meteor Hooks Kitchen Sink.jsx
Last active January 1, 2021 21:52
Meteor Hooks Kitchen Sink
import { useTracker } from 'meteor/react-meteor-data'
// Create a reusable subscribe hook
const usePageSubscription = (pageId) => useTracker(() => {
const subscription = Meteor.subscribe('page', pageId)
return !subscription.ready()
}, [pageId])
// Separate page hook
const usePage = (pageId) => useTracker(() => {
@CaptainN
CaptainN / Meteor Containers from Hooks.jsx
Last active January 28, 2020 20:48
Meteor Containers from Hooks
import { useTracker } from 'meteor/react-meteor-data'
// We can easily make old style HOCs out of the hooks
const withUser = (Component) => (props) => {
const accountProps = useAccount()
return <Component {...props} {...accountProps} />
}
const withPage = (Component) => (props) => (
const pageProps = usePage(props.pageId)
return <Component {...props} {...pageProps} />
@CaptainN
CaptainN / Meteor Prefab Hook.jsx
Last active January 28, 2020 20:48
Meteor Prefab Hook
import { useTracker } from 'meteor/react-meteor-data'
// Create a reusable hook
const usePage = (pageId) => useTracker(() => {
// The publication must also be secure
const subscription = Meteor.subscribe('page', pageId)
const page = Pages.findOne({ _id: pageId })
return {
page,
isLoading: !subscription.ready()
@CaptainN
CaptainN / Meteor Basic useTracker.jsx
Last active September 2, 2021 16:54
Meteor Basic useTracker
import { useTracker } from 'meteor/react-meteor-data'
// Hook, basic use, everything in one component
const MyPage = (pageId) => {
const { user, isLoggedIn, page } = useTracker(() => {
// The publication must also be secure
const subscription = Meteor.subscribe('page', pageId)
const page = Pages.findOne({ _id: pageId })
return {
page,
@CaptainN
CaptainN / Meteor Containers.jsx
Last active January 28, 2020 20:49
Meteor Containers
import { withTracker } from 'meteor/react-meteor-data'
// Create a reusable hook
const withAccount = withTracker((props) => {
const user = Meteor.user()
const userId = Meteor.userId()
return {
user,
userId,
isLoggedIn: !!userId
@CaptainN
CaptainN / Meteor Robust Prefab Hooks.jsx
Last active January 31, 2020 18:15
Meteor Robust Prefab Hooks
import { useTracker } from 'meteor/react-meteor-data'
// Create a reusable hook
const useAccount = () => useTracker(() => {
const user = Meteor.user()
const userId = Meteor.userId()
return {
user,
userId,
isLoggedIn: !!userId
@CaptainN
CaptainN / Meteor Robust useTracker.jsx
Last active March 12, 2020 21:33
Meteor Robust useTracker
import { useTracker } from 'meteor/react-meteor-data'
// Hook, basic use, everything in one component
const MyProtectedPage = (pageId) => {
const { user, isLoggedIn, page } = useTracker(() => {
// The publication must also be secure
const subscription = Meteor.subscribe('page', pageId)
const page = Pages.findOne({ _id: pageId })
const user = Meteor.user()
const userId = Meteor.userId()