简体   繁体   中英

How can I export a react material-ui component with

I would like to export a styled text link component using react and material-ui and withStyles , but my code returns:

Acorn error: Shorthand property assignments are valid only in destructuring patterns (14:9)

With the breakpoint on line 14

12  exports.default = styles_1.withStyles({
13      text,
14      type = "", // Error happens here
15      align = "",
16      className = "",
17      to = "",
18  })(styles);

Code referring to TextLink component:

import TextLink from '../components/TextLink'

<div>
    <TextLink to="/sign-up" type="body1" align="center" className="testing" text="Sign up" />
</div>

Textlink component:

import * as React from 'react';
import { Link } from "react-router-dom";
import Typography from 'material-ui/Typography';
import { withStyles } from 'material-ui/styles';
import * as PropTypes from 'prop-types'

const styles = {
  testing: {
    color: 'green'
  },
};

export default withStyles({
  text, 
  type = "",
  align = "",
  className = "",
  to = "",
})(styles) =>
  <Typography 
    type={`${type}`} 
    align={`${align}`}> 
      <Link
        to={`${to}`}
        className={`${className}`}
      > 
        {text}
      </Link>
  </Typography>;

Edit: As response to Timo's answer. The textlink component works fine without withstyles like this:

export default ({
  text, 
  type = "",
  align = "",
  className = "",
  to = ""
}) =>
  <Typography 
    type={`${type}`} 
    align={`${align}`}> 
      <Link
        to={`${to}`}
        className={`${className}`}
      > 
        {text}
      </Link>
  </Typography>;

This is simply not how you define an object in JS.

Use colons to separate the keys from the values:

exports.default = styles_1.withStyles({
    text,
    type: "",
    align: "",
    className: "",
    to: ""
})(styles);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM