Skip to content

Instantly share code, notes, and snippets.

View markodayan's full-sized avatar
🍑

Mark Odayan markodayan

🍑
View GitHub Profile
@markodayan
markodayan / graphql.sh
Created February 24, 2020 18:35
GraphQL Node server setup
#dependencies
npm install express graphql express-graphql lodash
@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 / materialize.sh
Created February 22, 2020 13:28
Materialize Stuff
# Installing dependency
npm install materialize-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 / 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 / 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 / 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 / react-fundamentals
Created February 14, 2020 13:50
Key React Principles
- Components
- Virtual DOM
- Lifecycle methods
- create-react-app
- HOCs
- Redux and Stores
@markodayan
markodayan / redirect.js
Created February 14, 2020 13:41
Redirecting to URL using props.history
handleClick = () => {
this.props.deletePost(this.props.post.id);
this.props.history.push('/'); // Redirect Action
};
@markodayan
markodayan / rootReducer.js
Created February 14, 2020 13:39
Basic Reducer Functionality (Dispatching Actions sent from components)
// initState defined beforehand in file or wherever and import it
const rootReducer = (state = initState, action) => {
if (action.type === 'DELETE_POST') {
let newPosts = state.posts.filter(post => action.id !== post.id);
return {
...state,
posts: newPosts
};