Skip to content

Instantly share code, notes, and snippets.

@urbanmarcen
Last active January 30, 2020 07:51
Show Gist options
  • Save urbanmarcen/17c315c8f2da3b76540379b6be37d6f2 to your computer and use it in GitHub Desktop.
Save urbanmarcen/17c315c8f2da3b76540379b6be37d6f2 to your computer and use it in GitHub Desktop.
A simple template for a Functional react component (with i18n, Redux, Material UI)
import React, { useState, useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
// Get context for services and actions
import context from "context/";
// Material UI
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
// Material UI styles
import { makeStyles } from "@material-ui/core/styles";
const useStyles = makeStyles(theme => ({
root: {
marginTop: 20
}
}));
const FunctionalComponent = props => {
const dispatch = useDispatch();
const { t } = props;
const { someInfo } = useSelector(state => ({
someInfo: state.some.info
}));
const [paramOne, setParamOne] = useState(props.paramOne);
/**
* Initial efects
*/
useEffect(() => {
// Unmount action
return () => {};
}, []);
// Other effects
return (
<Grid container>
<Grid item sm={12}>
<Typography variant="body1">Paragraph</Typography>
</Grid>
</Grid>
);
};
FunctionalComponent.defaultProps = {
paramOne: ""
};
export default FunctionalComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment