我正在尝试在我的应用程序上实现一个简单的地图,但在使用下面来自 React Leaflet 的示例代码时遇到此错误。
import React from "react";
import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet";
export default function App() {
return (
<MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
);
}
Run Code Online (Sandbox Code Playgroud)
错误:
Type '{ children: Element[]; center: number[]; zoom: number; scrollWheelZoom: boolean; }' is not assignable to type 'IntrinsicAttributes & MapContainerProps'.
Property 'center' does not exist on type …Run Code Online (Sandbox Code Playgroud) 在为我的 React.js 应用程序编写过滤器功能时,我遇到了以下问题:
由于我有三种不同类型的过滤器(日期、校园和城市),因此我必须仅根据用户填写的过滤器(可以只有其中一个、两个或三个)向用户返回一组对象. 为了解决这个问题,我想出了这个解决方案:
// Example of user input, something how my state variables should look
const date = null
const campus = "Example 1"
const city = "City 1"
//
const array = [ { date: "2020-11-23", campus: "Example 1", city: "City 1" },
{ date: "2020-11-24", campus: "Example 2", city: "City 2" }, ]
const filteredArray = array.filter(e => {
if (date && campus && city)
return e.date === date && e.campus === campus && e.city === …Run Code Online (Sandbox Code Playgroud)