How use the Theme properties in MakeStyles - css

I have this simple component:
import React from "react";
import { Grid } from "#mui/material";
import clsx from "clsx";
import theme from "../../theme";
// styling
import { makeStyles } from "#mui/styles";
const useStyles = makeStyles(() => ({
buildContainers: {
"&.MuiGrid-root": {
height: "calc(calc((100vmin - 64px)",
},
},
flowchartContainer: {
"&.MuiGrid-root": {
backgroundColor: theme.palette.secondary,
},
},
}));
const BuildSection: React.FC = () => {
const classes = useStyles();
return (
<Grid container>
<Grid item className={classes.buildContainers} xs={2.8}>
Tools
</Grid>
<Grid
item
className={clsx(classes.buildContainers, classes.flowchartContainer)}
xs={12 - 2.8}>
Flowchart
</Grid>
</Grid>
);
};
export default BuildSection;
I want to change the backgroundColor to a color from my theme, but I get [object object] in the console styling sheet and the background color is not changing. What am I doing wrong? if I use the spread operator, it works for other component.
my theme:
import { createTheme } from "#mui/material/styles";
import "#mui/material/styles";
import "#mui/material/styles/createPalette";
enum themePalette {
ARCBLACK = "#181824",
ARCGREY = "#f5f5f5",
}
enum typographyFonts {
H3 = 300,
}
// adding a field
declare module "#mui/material/styles" {
interface TypographyVariants {
buttonStyleHeader: React.CSSProperties;
buttonStyleHeaderHover: React.CSSProperties;
estimateBtn: React.CSSProperties;
}
// allow configuration using `createTheme`
interface TypographyVariantsOptions {
buttonStyleHeader?: React.CSSProperties;
buttonStyleHeaderHover?: React.CSSProperties;
}
}
// Update the Typography's variant prop options
declare module "#mui/material/Typography" {
interface TypographyPropsVariantOverrides {
buttonStyleHeader: true;
buttonStyleHeaderHover: true;
}
}
declare module "#mui/material/styles/createPalette" {
interface CommonColors {
// might need more colors here3
}
}
const theme = createTheme({
palette: {
primary: {
main: themePalette.ARCBLACK,
},
secondary: {
main: themePalette.ARCGREY,
},
},
typography: {
h3: {
fontWeight: typographyFonts.H3,
},
buttonStyleHeader: {
backgroundColor: themePalette.ARCGREY,
textTransform: "capitalize",
fontSize: 19,
},
buttonStyleHeaderHover: {
backgroundColor: themePalette.ARCBLACK,
color: "white",
},
},
});
export default theme;
I know that for MUI v17+ the makeStyles have been depricated, but I don't know why the theme won't take this theme property.

Related

Material-ui: Set tab background color based on passed prop to a styledTab

I have prepared this custom tab to style it as I want:
import { withStyles } from "#material-ui/core/styles";
const StyledTab = withStyles((theme) => ({
root: {
backgroundColor: "yellow",
},
}))((props) => {
const { shouldSetBackgroundColorToOrange } = props;
return <Tab {...props} />;
});
This is how it's used:
<StyledTab label={"Room"} shouldSetBackgroundColorToOrange={true} />;
I'd like to set its color to orange based on the shouldSetBackgroundColorToOrange prop that's passed to it.
But, I couldn't find a way to do this.
Have a look at the code below and in this working codesandbox
In using the button but you can easily adopt it in your code
import React from "react";
import { createStyles, makeStyles } from "#material-ui/core/styles";
import Button from "#material-ui/core/Button";
interface styleProps {
shouldSetBackgroundColorToOrange: boolean;
}
const useStyles = makeStyles((theme) =>
createStyles({
root: {
backgroundColor: ({shouldSetBackgroundColorToOrange}: styleProps) =>
shouldSetBackgroundColorToOrange ? "orange" : "yellow"
}
})
);
function TestComponent() {
const classes = useStyles({ shouldSetBackgroundColorToOrange: true });
return (
<Button variant="contained" className={classes.root}>
Button
</Button>
);
}
export default TestComponent;

Material-ui makeStyles overwritten by default

I am trying to override pseudo-classes in Stepper component using makeStyles:
const useStyles = makeStyles((theme) => ({
active: {
color: theme.palette.primary.main,
},
completed: {
color: theme.palette.goodyear.status.positive,
},
root: {
color: theme.palette.goodyear.grey.medium,
fontWeight: 500,
},
text: {
color: theme.palette.text.titles,
},
iconContainer: {
transform: 'scale(1.667)',
},
label: {
fontSize: '1.2rem',
fontWeight: 500,
},
}));
const StepLabel = (props) => {
const classes = useStyles();
return (
<MaterialStepLabel
classes={{
iconContainer: classes.iconContainer,
label: classes.label,
}}
StepIconProps={{
classes: {
active: classes.active,
completed: classes.completed,
root: classes.root,
text: classes.text,
},
}}
{...props}
/>
);
};
Unfortunately in the browser the results look like that:
The classes that were created by makeStyles are there, but are overridden by default because it's more specific? You can also see that the completed class is also below the root class, which would be strange, since root is the element in general state, and the completed pseudo should override that styles.
What could be the problem here and how should I use that classes correctly?
Below is the definition of the default styles for StepIcon:
export const styles = (theme) => ({
/* Styles applied to the root element. */
root: {
display: 'block',
color: theme.palette.text.disabled,
'&$completed': {
color: theme.palette.primary.main,
},
'&$active': {
color: theme.palette.primary.main,
},
'&$error': {
color: theme.palette.error.main,
},
},
/* Styles applied to the SVG text element. */
text: {
fill: theme.palette.primary.contrastText,
fontSize: theme.typography.caption.fontSize,
fontFamily: theme.typography.fontFamily,
},
/* Pseudo-class applied to the root element if `active={true}`. */
active: {},
/* Pseudo-class applied to the root element if `completed={true}`. */
completed: {},
/* Pseudo-class applied to the root element if `error={true}`. */
error: {},
});
The key to understanding the problems you are experiencing is to better understand how CSS specificity works.
In the styles above, you can see that all the states other than the default are applied via a declaration with two CSS class names. The & refers back to root and then $completed and $active refer to the corresponding rules defined via completed: {} and active: {}. As you saw when inspecting the styles, &$completed resolves eventually to be .MuiStepIcon-root.MuiStepIcon-completed.
The styles in a CSS declaration with two class selectors (e.g. .MuiStepIcon-root.MuiStepIcon-completed) will always win over styles in a CSS declaration with a single class selector (as is the case with all of your styles). When specificity is the same, such as with your makeStyles-root-x and makeStyles-completed-x, then the one declared last will win. You declared your root class after your completed class (and this relative ordering carries through to the stylesheet in the <head> generated for your makeStyles call), so your root class wins.
For your style overrides to work, you should use the same specificity as used in the default styles in Material-UI. I would recommend defining your root and completed styles as follows:
const useStyles = makeStyles((theme) => ({
root: {
color: theme.palette.goodyear.grey.medium,
fontWeight: 500,
"&.MuiStepIcon-completed": {
color: theme.palette.goodyear.status.positive,
},
},
}));
With this approach you don't need to specify anything for completed within the classes prop -- just root.
Below is a full working example based on one of the demos (the stepIconRoot class being the most relevant portion):
import React from "react";
import { makeStyles } from "#material-ui/core/styles";
import Stepper from "#material-ui/core/Stepper";
import Step from "#material-ui/core/Step";
import StepLabel from "#material-ui/core/StepLabel";
import Button from "#material-ui/core/Button";
import Typography from "#material-ui/core/Typography";
const useStyles = makeStyles((theme) => ({
root: {
width: "100%"
},
button: {
marginRight: theme.spacing(1)
},
instructions: {
marginTop: theme.spacing(1),
marginBottom: theme.spacing(1)
},
stepIconRoot: {
color: "orange",
"&.MuiStepIcon-active": {
color: "purple"
},
"&.MuiStepIcon-completed": {
color: "green"
}
}
}));
function getSteps() {
return ["Select campaign settings", "Create an ad group", "Create an ad"];
}
function getStepContent(step) {
switch (step) {
case 0:
return "Select campaign settings...";
case 1:
return "What is an ad group anyways?";
case 2:
return "This is the bit I really care about!";
default:
return "Unknown step";
}
}
export default function HorizontalLinearStepper() {
const classes = useStyles();
const [activeStep, setActiveStep] = React.useState(0);
const [skipped, setSkipped] = React.useState(new Set());
const steps = getSteps();
const isStepOptional = (step) => {
return step === 1;
};
const isStepSkipped = (step) => {
return skipped.has(step);
};
const handleNext = () => {
let newSkipped = skipped;
if (isStepSkipped(activeStep)) {
newSkipped = new Set(newSkipped.values());
newSkipped.delete(activeStep);
}
setActiveStep((prevActiveStep) => prevActiveStep + 1);
setSkipped(newSkipped);
};
const handleBack = () => {
setActiveStep((prevActiveStep) => prevActiveStep - 1);
};
const handleSkip = () => {
if (!isStepOptional(activeStep)) {
// You probably want to guard against something like this,
// it should never occur unless someone's actively trying to break something.
throw new Error("You can't skip a step that isn't optional.");
}
setActiveStep((prevActiveStep) => prevActiveStep + 1);
setSkipped((prevSkipped) => {
const newSkipped = new Set(prevSkipped.values());
newSkipped.add(activeStep);
return newSkipped;
});
};
const handleReset = () => {
setActiveStep(0);
};
return (
<div className={classes.root}>
<Stepper activeStep={activeStep}>
{steps.map((label, index) => {
const stepProps = {};
const labelProps = {
StepIconProps: { classes: { root: classes.stepIconRoot } }
};
if (isStepOptional(index)) {
labelProps.optional = (
<Typography variant="caption">Optional</Typography>
);
}
if (isStepSkipped(index)) {
stepProps.completed = false;
}
return (
<Step key={label} {...stepProps}>
<StepLabel {...labelProps}>{label}</StepLabel>
</Step>
);
})}
</Stepper>
<div>
{activeStep === steps.length ? (
<div>
<Typography className={classes.instructions}>
All steps completed - you&apos;re finished
</Typography>
<Button onClick={handleReset} className={classes.button}>
Reset
</Button>
</div>
) : (
<div>
<Typography className={classes.instructions}>
{getStepContent(activeStep)}
</Typography>
<div>
<Button
disabled={activeStep === 0}
onClick={handleBack}
className={classes.button}
>
Back
</Button>
{isStepOptional(activeStep) && (
<Button
variant="contained"
color="primary"
onClick={handleSkip}
className={classes.button}
>
Skip
</Button>
)}
<Button
variant="contained"
color="primary"
onClick={handleNext}
className={classes.button}
>
{activeStep === steps.length - 1 ? "Finish" : "Next"}
</Button>
</div>
</div>
)}
</div>
</div>
);
}

How to set material ui date picker size with media query for 4k resolution screen

I'm writing an application in React for 4k target device. the only problem is with the Material UI date picker - which seems tiny in 4k screens. How do I set its size with media queries?
Could not find any material on the subject. I tried something ( which is commented in the code I attached in this question.
import MomentUtils from '#date-io/moment';
import moment from 'moment';
import { MuiThemeProvider, createMuiTheme } from '#material-ui/core';
import {
DatePicker,
MuiPickersUtilsProvider,
} from 'material-ui-pickers';
import { greenAccept } from '../../colors';
const theme = createMuiTheme({
// props: {
// MuiWithWidth: {
// // Initial width property
// ['#media (min-width:2500px)']: { // eslint-disable-line no-useless-computed-key
// initialWidth: 'lg', // Breakpoint being globally set 🌎!
// },
// },
// },
typography: {
htmlFontSize: '16px',
['#media (min-width:2500px)']: { // eslint-disable-line no-useless-computed-key
fontSize: '32px',
},
},
overrides: {
MuiPickersToolbar: {
toolbar: {
backgroundColor: `${greenAccept}`,
},
},
MuiPickersDay: {
isSelected: {
backgroundColor: `${greenAccept}`,
'&:hover': {
backgroundColor: `${greenAccept}`,
},
},
current: {
color: `${greenAccept}`,
},
},
MuiPickersModal: {
dialogAction: {
color: `${greenAccept}`,
},
},
},
});
class DatePickComponent extends React.Component {
handleDateChange = (date) => {
this.setState({
});
if (this.props.selectedDateHandler) {
this.props.selectedDateHandler(date);
}
}
formatWeekSelectLabel = () => {
const { title } = this.props;
if (this.props.date) {
return moment(this.props.date).format('DD/MM/YYYY');
}
return `${title}`;
}
render() {
return (
<MuiPickersUtilsProvider utils={MomentUtils}>
<MuiThemeProvider theme={theme}>
<DatePicker
readOnly
labelFunc={this.formatWeekSelectLabel}
onChange={this.handleDateChange}
animateYearScrolling
InputProps={{
disableUnderline: true,
}}
/>
</MuiThemeProvider>
</MuiPickersUtilsProvider>
);
}
}
export default DatePickComponent;
the expecteed results will be to the datepicker to show like its current size in the user laptop, but show much bigger in 4k screens

Changing styles during clicking

I have ReactJS project and I want to change colour of button during clicking. I know that it is a Ripple API but it's very incomprehensible to use it. Could someone advise me how can I do that?
I've tried to create two elements - parent and child - and changed background of child to transparent while clicking. Unfortunately I have also 'classes' object responsible for changing class if button is active and it is just not working.
My code below:
import React, { Component } from 'react';
import { withStyles } from '#material-ui/core/styles';
import Button from '#material-ui/core/Button';
import PropTypes from 'prop-types';
import styles from './MydButton.style';
class MyButton extends Component {
constructor(props) {
super(props);
this.state = {
isClicked: false
};
}
handleClick = () => {
this.setState({ isClicked: !this.state.isClicked });
}
render() {
const {
classes,
children,
color,
disabled,
className,
onClick,
type,
border,
...props
} = this.props;
const myClass = this.state.isClicked ? 'auxClass' : 'buttonDefaultRoot';
return (
<div className={classes.parentRoot} >
<Button
classes={{
root: disabled
? classes.buttonDisabledRoot
: classes.buttonRoot,
label: disabled
? classes.buttonLabelDisabled
: classes.buttonLabel,
}}
{...props}
onClick={this.handleClick}
className={myClass}
disabled={disabled}
type={type === undefined ? 'button' : type}
>
{children}
</Button>
</div>
)
}
};
MyButton.propTypes = {
children: PropTypes.string.isRequired,
disabled: PropTypes.bool,
classes: PropTypes.object.isRequired,
};
MyButton.defaultProps = {
disabled: false,
};
export default withStyles(styles)(MyButton);
and styles:
const buttonRoot = {
border: 0,
height: 48,
width: '100%',
}
export default theme => ({
buttonDefaultRoot: {
...buttonRoot,
transition: 'all 1s ease-in-out',
backgroundImage: 'linear-gradient(to right, #F59C81, #E65DA2, #E65DA2, #B13A97, #881E8E)',
boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.16)',
backgroundSize: '300% 100%',
marginTop: 0,
'&:hover': {
backgroundPosition: '100% 0%',
transition: 'all 1s ease-in-out',
}
},
parentRoot: {
...buttonRoot,
backgroundColor: 'red',
backgroundSize: '300% 100%',
marginTop: 36,
},
auxClass: {
backgroundImage: 'none',
},
Material UI Core for ReactJS
The documentation is very good. I have updated my answer to accomodate the specific needs of this question. I have also included two general solutions for anyone who stumbles upon this question.
Tailored Solution:
Changes background color of button from classes.buttonDefaultRoot (a color defined by owner of question) to the gradient defined by the owner of this question.
First step, have a variable stored in state. You can call it whatever you want, but I'm calling bgButton. Set this to this.props.classes.buttonDefaultRoot like so:
state = {
bgButton: this.props.classes.buttonDefaultRoot,
}
Next, you want to define your function that will handle the click. Again, call it what you want. I will call it handleClick.
handleClick = () => {
const { classes } = this.props; //this grabs your css style theme
this.setState({ bgButton: classes.parentRoot.auxClass }); //accessing styles
};
A couple of things are happening here. First, I am destructuring props. So, I am creating a new const variable called classes that has the same value as this.props.classes. The classes contains a set of objects that defines your css styles for your buttons, margins, etc. You can access those styles just like you would if you were trying to get the value of a prop in an obj.
In this case you can access your button style by doing, classes.buttonDefaultRoot. That takes care of your handle click function.
Last step: render the button. In your render method you want to grab your bgButton from state like so:
render() {
const { bgButton } = this.state;
Then you want to assign your className of your button to bgButton and add the onClick functionality like this (this follows the Material UI Core documentation):
<Button variant="contained" color="primary" className={classNames(bgButton)} onClick={this.handleClick}>Button Name</Button>
Putting it all together you get this:
import React, { Component } from "react";
import Button from "#material-ui/core/Button";
import PropTypes from "prop-types";
import classNames from "classnames";
import { withStyles } from "#material-ui/core/styles";
export default theme => ({ ... }) //not going to copy all of this
class MyButton extends Component {
state = {
bgButton: null
};
handleClick = () => {
const { classes } = this.props;
this.setState({ bgButton: classes.parentRoot.auxClass });
};
render() {
const { bgButton } = this.state;
return (
<div className={classes.container}>
<Button
variant="contained"
color="primary"
className={classNames(bgButton)}
onClick={this.handleClick}
>
Custom CSS
</Button>
</div>
);
}
}
MyButton.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(MyButton);
General Solution
This solution is for those who want to use the predefined colors, i.e. default, primary, secondary, inherit. This implementation does not need the PropTypes or className imports. This will change the color from the predefined blue to the predefined pink. That's it.
state = {
bgButton: "primary",
}
handleClick = () => {
this.setState({ bgButton: "secondary" });
}
render() {
const { bgButton } = this.state;
return(
...
<Button
onClick = {this.handleClick}
variant = "contained" //checked Material UI documentation
color={bgButton}
> ..etc.
General Solution 2
To accommodate your custom styles to the button, you would have to import PropTypes and classNames and take a similar approach as the tailored solution above. The only difference here will be my syntax and class name. I am closely following the documentation here so you can easily follow along and readjust where necessary.
import React, { Component } from "react";
import Button from "#material-ui/core/Button";
import PropTypes from "prop-types";
import classNames from "classnames";
import { withStyles } from "#material-ui/core/styles";
import purple from "#material-ui/core/colors/purple";
const styles = theme => ({
container: {
display: "flex",
flexWrap: "wrap"
},
margin: {
margin: theme.spacing.unit
},
cssRoot: {
color: theme.palette.getContrastText(purple[500]),
backgroundColor: purple[500],
"&:hover": {
backgroundColor: purple[700]
}
},
bootstrapRoot: {
boxShadow: "none",
textTransform: "none",
fontSize: 16,
padding: "6px 12px",
border: "1px solid",
backgroundColor: "#007bff",
borderColor: "#007bff",
fontFamily: [
"-apple-system",
"BlinkMacSystemFont",
'"Segoe UI"',
"Roboto",
'"Helvetica Neue"',
"Arial",
"sans-serif",
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"'
].join(","),
"&:hover": {
backgroundColor: "#0069d9",
borderColor: "#0062cc"
},
"&:active": {
boxShadow: "none",
backgroundColor: "#0062cc",
borderColor: "#005cbf"
},
"&:focus": {
boxShadow: "0 0 0 0.2rem rgba(0,123,255,.5)"
}
}
});
class MyButton extends Component {
state = {
bgButton: null
};
handleClick = () => {
const { classes } = this.props;
this.setState({ bgButton: classes.cssRoot });
};
render() {
const { classes } = this.props; //this gives you access to all styles defined above, so in your className prop for your HTML tags you can put classes.container, classes.margin, classes.cssRoot, or classes.bootstrapRoot in this example.
const { bgButton } = this.state;
return (
<div className={classes.container}>
<Button
variant="contained"
color="primary"
className={classNames(bgButton)}
onClick={this.handleClick}
>
Custom CSS
</Button>
</div>
);
}
}
MyButton.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(MyButton);
A tip. You no longer need a constructor or to bind methods.
Hope this helps.

expo react-native react-navigation react-intl how to trigger an update to the messages once the user locale is resolved

I am using expo, react-native, redux, react-navigation, and react-intl. Expo has this async Localization.getCurrentLocaleAsync() function to retrieve the locale asynchronously. I encountered problem propagating changes of locale and messages down to child components.
For example, if I set initial locale to "es" in "Root.js", when the Localization.getCurrentLocaleAsync() kick in and set the locale to "en", the updated messages was not reflected in the child component "Login.js". As such, the simulator throws a console.error: Missing message: "Login.login" for locale: "es", using default message as fallback while I updated the locale and message in the root.js state Here's my code:
root.js
import React from 'react';
import { Provider } from 'react-redux';
import { StyleSheet, Text, View, Alert } from 'react-native';
import { DangerZone } from 'expo';
import { IntlProvider, addLocaleData, injectIntl } from 'react-intl';
import { createBottomTabNavigator, createSwitchNavigator } from 'react-navigation';
import { PersistGate } from 'redux-persist/integration/react';
import AuthLoadingPage from './containers/authLoading';
import LoginPage from './containers/login';
import SignupPage from './containers/signup';
import HomePage from './containers/home';
import NotFoundPage from './containers/notFound';
import configureStore from './configureStore';
import en from 'react-intl/locale-data/en';
import es from 'react-intl/locale-data/es';
import localeData from './build/data.json';
addLocaleData([...en, ...es]);
const { Localization } = DangerZone;
const { persistor, store } = configureStore();
const AuthTab = createBottomTabNavigator({
login: { screen: LoginPage },
signup: { screen: SignupPage },
},{
navigationOptions: {
tabBarVisible: false,
},
lazyLoad: true,
});
const MainNavigator = createSwitchNavigator({
authLoading: AuthLoadingPage,
main: { screen: HomePage},
auth: AuthTab,
},{
initialRouteName: 'authLoading',
});
class Root extends React.Component {
constructor(p) {
super(p);
this.state = {
currentLocale: 'es',
messages: localeData['es'],
};
}
componentDidMount() {
Localization.getCurrentLocaleAsync()
.then(currentLocale => {
console.log("currentLocale is >>>", currentLocale);
this.setState({
currentLocale,
messages: localeData[currentLocale],
});
});
}
render() {
console.log("this.state.message???", this.state.messages);
return (
<IntlProvider
locale={this.state.currentLocale}
key={this.state.currentLocale}
messages={this.state.messages}
textComponent={Text}
>
<Provider store={store}>
<PersistGate
loading={<NotFoundPage />}
onBeforeLift={() => {}}
persistor={persistor}
>
<MainNavigator />
</PersistGate>
</Provider>
</IntlProvider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default Root;
and "containers/Login.js":
import React, { Component } from 'react';
import { injectIntl, intlShape, FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import {
View,
Text,
TextInput,
Image,
Dimensions,
KeyboardAvoidingView,
StyleSheet,
Button,
TouchableOpacity
} from 'react-native';
import { FormLabel, FormInput } from 'react-native-elements';
import { authenticate } from '../modules/auth/actions';
const SCREEN_WIDTH = Dimensions.get('window').width;
class LoginPage extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: ''
};
}
handleSubmit(e) {
e.preventDefault();
const { email, password } = this.state;
const { navigation } = this.props;
this.props.dispatch(authenticate(email, password))
.then(() => {
navigation.navigate('main');
})
}
gotoSignup(e) {
e.preventDefault();
const { navigation } = this.props;
navigation.navigate('signup');
}
render() {
const { isAuthenticated, navigation } = this.props;
return (
<KeyboardAvoidingView behavior="padding" style={styles.container}>
<View style={styles.loginLogo}>
<FormattedMessage
id={ 'Login.login' }
defaultMessage={ 'Welcome to login screen!' }
/>
</View>
</KeyboardAvoidingView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
width: Dimensions.get('window').width,
},
loginLogo: {
flex:1,
},
loginForm: {
flex: 2,
},
loginFormContainer: {
flex: 1,
padding: 20,
},
input: {
height: 40,
backgroundColor: 'rgba(255,255,255, 0.8)',
paddingLeft: 10,
marginBottom: 15,
},
buttoncontainer: {
backgroundColor: '#23618C',
marginTop: 10,
paddingVertical: 15,
},
buttontext: {
textAlign: 'center',
color: '#fff',
fontWeight: 'bold',
},
});
function mapStateToProps(state) {
const { auth } = state;
const { loading, isAuthenticated } = auth;
return {
loading,
isAuthenticated
};
}
export default connect(mapStateToProps)(LoginPage);
you can also find the relavent code in github:
root.js: https://github.com/7seven7lst/mobile-client-new/blob/master/root.js
containers/Login.js: https://github.com/7seven7lst/mobile-client-new/blob/master/containers/login.js
Never mind. the above should be working. I got this id messed up. it should be "Login.Login" because that's what I have in the data.json file.
<FormattedMessage
id={ 'Login.login' }
defaultMessage={ 'Welcome to login screen!' }
/>

Resources