Skip to content

Instantly share code, notes, and snippets.

View jamesattard's full-sized avatar

James A. jamesattard

View GitHub Profile
...
class PostList extends Component {
async componentDidMount() {
const { fetchPostsAndData } = this.props;
await fetchPostsAndData();
}
renderPosts = () => {
const postList = this.props.postList;
export const fetchPostsAndComments = () => async (
dispatch,
getState
) => {
await dispatch(fetchPostList());
const PostList = await getState().post.postList;
await PostList.forEach(post => {
dispatch(fetchPostComments(post._id));
});
};
@jamesattard
jamesattard / timeRangeMoment.js
Created May 8, 2018 19:53
Create a moment.js time range based on arbitrary duration, start time and end time
const timeRangeArr = [];
const lunchBreakFrom = moment()
.hours(12)
.minutes(0);
const lunchBreakTo = moment()
.hours(13)
.minutes(0);
const duration = 15;
for (
const counter = 5;
[...Array(counter)].forEach(
(_, i) => {
console.log(i);
}
)
@jamesattard
jamesattard / rename_git_branch.sh
Created April 2, 2018 23:08
Rename git branch
git branch -m old_branch new_branch
git push --set-upstream origin new_branch
git push origin :old_branch
class MyComponent extends Component {
componentDidUpdate() {
if (!!this.props.payload.success) {
this.props.actionCreator();
this.props.history.push("/Dashboard");
}
}
render() {
return (
class MyComponent extends Component {
handleNewSubscription = () => {
this.props.actionCreator();
return <Redirect to="/dashboard" />;
};
render() {
!!this.props.payload.success ? this.handleNewSubscription() : null
return (
...
)
@jamesattard
jamesattard / component.js
Created March 28, 2018 22:49
trigger action creator after state completes mutation
class MyComponent extends Component {
render() {
if (!!this.props.payload.success) {
this.props.actionCreator();
return <Redirect to="/dashboard" />;
}
return (
...
)
}
export const handleProviderToken = token => async (dispatch, getState) => {
const testState = getState()
console.log(testState.auth);
dispatch({ type: TEST });
};
import { combineReducers } from "redux";
import { reducer as reduxForm } from "redux-form";
import authReducer from "./authReducer";
export default combineReducers({
auth: authReducer,
form: reduxForm
});