[英]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.