Skip to content

Instantly share code, notes, and snippets.

View markodayan's full-sized avatar
🍑

Mark Odayan markodayan

🍑
View GitHub Profile
@markodayan
markodayan / routes.js
Last active February 14, 2020 20:03
React Routing Snippets
// 1) To ensure that paths are not accidently accessed - use 'exact' attribute on a Route
<Route exact path='/' component={Dashboard} />
// 2) If Routing to a functional component, the props of it contain information about the route, check with console.log
console.log(props) // in the functional comp -> eg props.match.params to get nav params from URL path
console.log(props.match.params);
// 3)
@markodayan
markodayan / asyncRedux.js
Last active February 15, 2020 20:08
Asynchronous Code with redux-thunk (halting dispatch)
// When we want to request information from a server, we do this within dispatching an action by asynchronously fetching
// data then dispatching to a reducer to alter app state.
// We achieve this with Redux middleware called 'redux-thunk'
// 'redux-thunk' allows you to call asynchronous tasks within action creators (dispatching actions). It halts the dispatch
// , performs the async request, then resumes the dispatch
// To use thunk it requires the 'applyMiddleware' method from 'redux'
// Thereafter it is applied to the store created as shown below:
@markodayan
markodayan / script.sh
Created February 21, 2020 21:30
Some random development commands
# SASS/SCSS automated compilation to CSS on save
sass --watch src/App.scss:src/App.css
@markodayan
markodayan / react.sh
Created February 21, 2020 22:06
A collection of various optional modules to use in React
# Route, Link from react
npm install react-router-dom
# Some redux dependencies in React ( also thunk for async actions)
npm install redux react-redux redux thunk
# Firebase and redux middleware for Firebase and its features
npm install firebase react-redux-firebase redux-firestore
# React build and deploying to Netlify
npm run build
netlify deploy --prod
@markodayan
markodayan / materialize.sh
Created February 22, 2020 13:28
Materialize Stuff
# Installing dependency
npm install materialize-css
@markodayan
markodayan / git.sh
Created February 24, 2020 13:30
Git Commands etc
# add remote
git remote add origin <remote-link>
git add .
git commit -m "<commit message>"
git push -u origin master
@markodayan
markodayan / graphql.sh
Created February 24, 2020 18:35
GraphQL Node server setup
#dependencies
npm install express graphql express-graphql lodash
@markodayan
markodayan / dev-resources.txt
Created February 25, 2020 19:55
Developer Resources and Useful References
www.easings.net [CSS Animation and Transition Timing Functions]
caniuse.com [CSS Feature compatibility with browsers]
mydevice.io [Device screen resolution pixel conversions]
shouldiprefix.com [Future proofing CSS]
sass-lang.com [sass documentation]
@markodayan
markodayan / useForm.js
Last active March 5, 2020 21:59
Custom Hooks in React (Form Input State Management)
import { useState } from 'react';
export const useForm = initialValues => {
const [values, setValues] = useState(initialValues);
return [
values,
e => {
setValues({
...values,
@markodayan
markodayan / useForm.js
Created March 5, 2020 21:33
Custom Hooks in React (Form Input State Management)
import { useState } from 'react';
export const useForm = initialValues => {
const values, setValues[ = useState(initialValues);
return [
values,
e => {
setValues({
...values,