如果我们在 ionic-react 中编写 jsx 语法会发生什么?是state={}
对象并且props
在 .tsx 文件中有效。我使用 .jsx 文件而不是 .tsx 创建前端,它会不会在部署中造成麻烦,如果是这样的话。我如何在不依赖打字稿的情况下克服这个问题?
import React, { Component } from "react";
import { IonGrid, IonRow, IonCol, IonButton } from "@ionic/react";
import LocationComp from "../comon/locationComp";
class Tab1_react extends Component {
state = {
province: [{ id: 1, name: "Western province" }],
district: [
{ id: 1, name: "Kaluthara" },
{ id: 2, name: "Colombo" },
{ id: 3, name: "Gampaha" },
],
};
render() {
return (
<IonGrid>
{/* 1 row */}
<IonRow>
<IonCol>
<LocationComp
data={this.state.province}
type="Province"
name="name"
id="id"
/>
</IonCol>
</IonRow>
{/* 2 row */}
<IonRow>
<IonCol>
<LocationComp
data={this.state.district}
type="District"
name="name"
id="id"
/>
</IonCol>
</IonRow>
{/* 3 row */}
<IonRow>
<IonCol>
<LocationComp
data={[{ id: 1, name: "Not Yet" }]}
type="Town"
name="name"
id="id"
/>
</IonCol>
</IonRow>
{/* 4 row */}
<IonRow>
<IonCol>
<IonButton fill="outline" expand="block" color="primary">
Search
</IonButton>
</IonCol>
</IonRow>
</IonGrid>
);
}
}
export default Tab1_react;
我做了一个反应组件调用 locationComp
import React, { Component } from "react";
import {
IonButton,
IonSelect,
IonSelectOption,
IonItem,
IonLabel,
} from "@ionic/react";
class LocationComp extends Component {
state = {};
render() {
const {data,name,id,type} = this.props;
return (
<IonItem>
<IonLabel>{type}</IonLabel>
<IonSelect
//value={gender}
placeholder="Select One"
// onIonChange={(e) => setGender(e.detail.value)}
>
{data.map(e=>(
<IonSelectOption key={e["id"]} value="female">{e["name"]}</IonSelectOption>
))}
</IonSelect>
</IonItem>
);
}
}
export default LocationComp;