1

我是一个 React Native 菜鸟,不知道如何让它工作:

import React from 'react'
import { View, Text } from 'react-native'

const Block = () => {
return (<Text>1</Text>);
}

const Noti = <Block />;

const Result = () => {
  
  let content

  if (Noti == 1) {
    content = <Text style={{ fontSize: 24, color: 'red' }}>One!</Text>
  } else if (Noti == 2) {
    content = <Text style={{ fontSize: 24, color: 'gray' }}>Two!!</Text>
  } else if (Noti == 3) {
    content = <Text style={{ fontSize: 24, color: 'gray' }}>Three!!!</Text>
  }

  return <View style={{ padding: 24 }}>{content}</View>
}

export default Result;

const Block将是一个导入的组件。该导入的组件将是 1 - 3 之间的数字。

如果该数字为 1,则内容 =“一个!”。如果该数字是 2,则内容 =“两个!”……等等。

的工作const Noti是简单地读取该数字并将其传递给const Result.

我怎样才能解决这个问题?

谢谢!

4

0 回答 0