[英]Is there any native way to render imported SVG as prop with map function in React?
[英]Render if prop changes in React Native Function
是否有可能在 React Native Function 中呈现更改时的“返回”? 我尝试什么:
我有一个 Function - 这个 Function 从另一个 Function 中获取一个特定的数组 - 在按钮按下我生成一个新的索引 - 现在我想用新的索引显示数组元素:
const generateNewIndex = function (item) {
return Math.floor(Math.random() * item.length);
};
const PositionItem = ({ arr, position, navigation }) => {
let { name, beschreibung, arten, rooms, isStarred } = position;
let testArray = arr;
let i = 0;
return (
<View style={styles.posContainer}>
<View style={styles.titles}>
<Text style={styles.title}>{name}</Text>
<Text style={styles.subtitle}>{beschreibung}</Text>
<Text style={styles.title}>{testArray[i].name}</Text>
</View>
<View style={styles.buttonsContainer}>
<StyledButton
type="primary"
content={"Next Random Position"}
onPress={() => {
console.warn("Pressed");
i = generateNewIndex(testArray);
}}
/>
</View>
</View>
);
};
export default PositionItem;
提前致谢!
我找到了一种有效的方法。 如果有人想知道未来我做了什么:
添加一个使用 State 组件:
const [count, setCount] = useState(0);
onPress on Button 增加计数:
onPress={() => {
i = generateNewIndex(array);
setCount((prevCount) => prevCount + 1);
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.