2016-04-05 10 views
2

私はshouldComponentUpdate、 でパフォーマンスを最適化したいですが、npm i react-addons-pure-render-mixin --saveの後にPureRenderMixinを正しく呼び出すことができません。使用可能なPureRenderMixinは反応ネイティブで

私はreact document ES6の手順に従います。

import PureRenderMixin from 'react-addons-pure-render-mixin'; 

class FooComponent extends React.Component { 
    constructor(props) { 
    super(props); 
    this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); 
    } 
} 

常にUnable to resolve module react-addons-pure-render-mixinエラーが発生します。

反応したネイティブの可能性はありますか?PureRenderMixinもしそうなら、私はそれをどのように修正すべきですか?

+0

'react-addons-pure-render-mixin'をインストールしましたか?それはインストールされていないように聞こえる。 –

+0

@CarlVitulloはい、私は 'react-addons-pure-render-mixin'をインストールします。私の事務用エラー –

答えて

0

'react-mixin'からreactMixinをインポートする必要があります。ソリューション全体は次のようになります:

import React, { Component } from 'react'; 
import { View } from 'react-native'; 
import reactMixin from 'react-mixin'; 
import PureRenderMixin from 'react-addons-pure-render-mixin'; 

import Styles from './styles'; 

export default class Loading extends Component { 

    render() { 
    return (
     <View style={Styles.container}> 
      <Text>Hello world!!!</Text> 
     </View> 
    ); 
    } 
} 

reactMixin(Loading.prototype, PureRenderMixin); 
+0

さらに読むために、関数reactMixinにデコレータ@を適用することができます。これが役に立つと願っています。 – user7532779

関連する問題