hi i am new to react native. I get this error when i start the app:
"TypeError: Attempted to assign to readonly property.
This error is located at:
in MyClass (at renderApplication.js:35)
in RCTView (at View.js:112)
in View (at AppContainer.js:102)
in RCTView (at View.js:112)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:34)
stopTracking
AnimatedValue.js:279:9
start
AnimatedImplementation.js:188:4"
on this code. Can somebody help me ? I cant find what is wrong with this code. I tried to restart npm react native server but it is still not working. The App should only transform a text from one position to another.
//import liraries
import React, { Component } from 'react';
import { View, Text, StyleSheet, Animated } from 'react-native';
// create a ponent
class MyClass extends Component {
constructor(){
super()
this.animated = new Animated.Value(0);
}
ponentDidMount() {
Animated.timing(this.animated,{
toValue:1,
duration: 2000,
}).start();
}
render() {
const translateX = this.animated.interpolate({
inputRange: [0,1],
outputRange:[-500,1]
});
const transfrom = [{translateX}];
return (
<View>
<Animated.Text style={[{transfrom}]}>
Hello
</Animated.Text>
</View>
);
}
}
// define your styles
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2c3e50',
},
});
//make this ponent available to the app
export default MyClass;
hi i am new to react native. I get this error when i start the app:
"TypeError: Attempted to assign to readonly property.
This error is located at:
in MyClass (at renderApplication.js:35)
in RCTView (at View.js:112)
in View (at AppContainer.js:102)
in RCTView (at View.js:112)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:34)
stopTracking
AnimatedValue.js:279:9
start
AnimatedImplementation.js:188:4"
on this code. Can somebody help me ? I cant find what is wrong with this code. I tried to restart npm react native server but it is still not working. The App should only transform a text from one position to another.
//import liraries
import React, { Component } from 'react';
import { View, Text, StyleSheet, Animated } from 'react-native';
// create a ponent
class MyClass extends Component {
constructor(){
super()
this.animated = new Animated.Value(0);
}
ponentDidMount() {
Animated.timing(this.animated,{
toValue:1,
duration: 2000,
}).start();
}
render() {
const translateX = this.animated.interpolate({
inputRange: [0,1],
outputRange:[-500,1]
});
const transfrom = [{translateX}];
return (
<View>
<Animated.Text style={[{transfrom}]}>
Hello
</Animated.Text>
</View>
);
}
}
// define your styles
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2c3e50',
},
});
//make this ponent available to the app
export default MyClass;
Share
Improve this question
asked Dec 19, 2017 at 22:01
ottootto
2,0638 gold badges42 silver badges69 bronze badges
1
-
have you tried passing
props
to theconstructor(props)
andsuper(props)
– Aaqib Commented Dec 19, 2017 at 22:16
1 Answer
Reset to default 6You misspelled transform.
render() {
const translateX = this.animated.interpolate({
inputRange: [0,1],
outputRange:[-500,1]
});
const transfrom = [{translateX}];
return (
<View>
<Animated.Text style={[{transfrom}]}>
Hello
</Animated.Text>
</View>
);
}