2

作成中のアプリに React DnD を追加していますが、次の構文では ES7 デコレータが (私が知る限り) 機能しないことに気付きました。

@DragDropContext(HTML5Backend)
export class App extends React.Component {
    ...
}
App.displayName = 'My App'

それでも、行を削除すればApp.displayNameすべて問題ありません。なんで?

displayName プロパティはどのように設定すればよいですか?

4

1 に答える 1

3

すでに ES7 の機能を使用しているため、ES7クラスのプロパティを使用できます。これらはステージ0です。

@DragDropContext(HTML5Backend)
export class App extends React.Component {
    static displayName = 'My App';
    //or just
    //displayName = 'My App';
}

バベルを使用している場合は、次を使用して機能を有効にする必要があります

babel --stage 0

また

babel --optional es7.classProperties
于 2015-08-18T10:29:11.360 に答える