2017-12-18 3 views
0
var Square = React.createClass({ 
    render: function() { 
    return (
     <View style={styles.square} /> 
) 
} 
}); 
square: { 
    width: 100, 
    height: 100, 
    backgroundColor: 'red' 
} 

실행하려고하면 "번들로드 실패"오류가 발생합니다.반응 원시에서 변수를 사용하려면 어떻게해야합니까?

var Card = React.createClass({ 
    render: function() { 
    var card = this.props.card; 

    return (
    <View style={styles.card}> 
    <Text numberOfLines={2} ref="definition" style={styles.definition}>{card.definition}</Text> 
    <Text numberOfLines={1} style={styles.chinese}>{this.props.simplified ? card.simplified : card.traditional}</Text> 
    <Text ref="pinyin" numberOfLines={1} style={styles.pinyin}>{card.pinyin}</Text> 
    </View> 
); 
}, 
}); 

나는 (온라인에서 찾은이 코드와 비슷한) 것을 만들려고 시도하고 있지만이 변형을 만들었지 만 여전히 실행되지 않습니다. 누군가가 내게 그 문제가 무엇인지 설명 할 수 있을까요? 고맙습니다.

+0

어떤 버전의 React를 사용하고 있습니까? – Max

+0

죄송합니다. 이것은 네이티브 반응입니다. 반응성 태그를 붙이면 안돼. – alphamonkey

+0

어떤 버전의 React Native를 사용하고 있습니까? – asubanovsky

답변

0

이것이 유일한 문제인 경우 확실하지 않지만 React.createClass은 더 이상 사용되지 않으며 최신 버전의 React (React Native uses React)에서 제거되었습니다.

React.createClass 대신 ES6 클래스와 기능적, 상태 비 저장 구성 요소를 사용해야합니다.

class Card extends React.Component { 
    render() { 
    return (
     <Text>Class Component</Text> 
    ) 
    } 
} 

function Square(props) { 
    return (
    <Text>Functional Component</Text> 
) 
} 

여전히 React.createClass를 사용하려면

, 당신이 할 수 있지만, 자체 패키지로 제공된다.

https://reactjs.org/blog/2017/09/26/react-v16.0.html

관련 문제