2016-10-19 6 views
0

Reactにはかなり新しいです。私はそれの中にいくつかのカスタムコンポーネントを持っているカスタムコンポーネントを作成したい。以下はundefinedはGoogleにこの問題を試みたが、何も見つからなかっしまっContainerコンポーネントとClickableTextコンポーネントprops.style内部コードReact子コンポーネントには未定義のprops.styleがあります。

const { item, to, onClick, width, style, ...otherProps } = props; 
const h = width ? (width*IMAGE_RATIO)+'px' : 'auto'; 
const w = width ? width+'px' : 'auto'; 
<StackView 
    style={{ width: w, ...style }} 
    {...otherProps} 
> 
    <Container 
    to={to} 
    onClick={onClick} 
    item={item} 
    style={{ width: w, height: h }} 
    /> 
    <ClickableText 
    to={to} 
    onClick={onClick} 
    typography={typography.t15} 
    color={color.red} 
    activeColor={color.redDark} 
    style={{ lineHeight: '12px' }} 
    > 
    {item.title} 
    </ClickableText> 
</StackView> 

です。誰かが私を助けることができますか?おかげ

EDIT:

Michael答えは上のスポットしました。問題は私のStackViewコンポーネントです。クローン作成中に子スタイルをオーバーライドします。

答えて

2

私はContainerClickableTextコンポーネントの親に何か問題があると確信しています。

親コンポーネントStackViewを確認してください。子供のスタイルをオーバーライドすると、それはこの混乱の根本的な問題です。

Good Luck。

-1

コンポーネントがステートレス機能コンポーネントでない場合は、this.props.styleを使用してプロパティにアクセスする必要があります。ここではコンポーネントの種類の

より: https://tylermcginnis.com/functional-components-vs-stateless-functional-components-vs-stateless-components-630fdfd90c9c

+0

ステートレスコンポーネントです。すべて – Ansel

+0

です。それから、 'this.props.style 'は期待どおりに動作するはずです –

関連する問題