私は、このコンポーネントを持っている:JSX印刷テキスト
<Button type="submit" { invalid ? 'primary': null }>
このコンポーネントはコンポーネントスタイル設定さ:
import styled from 'styled-components';
export const Button = styled.button`
font-size: 15px;
padding: 0.25em 1em;
border: solid 1px ${(props) => {
let color;
if (props.primary) {
color = 'red';
} else {
color = '#ffffff';
}
return color;
}};
`;
私はこのエラーを取得する:
Syntax error: Unexpected token ^invalid, expected ... (64:54)
無効になっている場合は、「プライマリ」プロパティを送信して、これを取得する必要があります。
<Button type="submit" primary/>
私が書き込みをしたくない:
primary = { invalid }
コンポーネントは、このボタンは呼び出します。
import React from 'react';
import { Button } from './layouts/cssstyled';
const getConditionalProps = (props) => {
// fill your `invalid` variable in this function or pass it to it
const myprops = {};
myprops.primary = true ;
myprops.secondary = false;
return myprops;
}
const Form = (props) => {
console.log('form props');
console.log(props);
const { handleSubmit, invalid, pristine, reset, submitting, t } = props;
return (
<form onSubmit={handleSubmit}>
<p>Invalid? {JSON.stringify(invalid)}</p>
<Button type="submit" disabled={submitting} primary={invalid ? "" : null} >
Buton styled component does not work
</Button>
<button primary={invalid ? "" : null}> button native works</button>
<div className="formError">
{pristine}
{invalid && t('form.haserrors')}
</div>
</div>
</form>
);
};
export default reduxForm({
form: 'CustomerForm', // a unique identifier for this form
})(Form);
'primary = {invalid}'と書くのは間違いありません。それを書かない理由がありますか? – ZekeDroid
私は「プライマリ」を必要とするCSSライブラリを使用していますが、jsxでテキストを印刷できない技術的な理由はなぜですか? – DDave
@DDave reactは印刷ライブラリではないため、HTMLにレンダリングされる仮想DOMです。 – Sulthan