admin管理员组文章数量:1122832
I am using react leaflet in my react app. I used context api to build my project. But when i tried using the leaflet using code :
<MapContainer center={position} zoom={13} scrollWheelZoom={false}>
<TileLayer
attribution='© <a href=";>OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap/{z}/{x}/{y}.png"
/>
<Marker position={position}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
I get errors like :
1.A context consumer was rendered with multiple children, or a child that isn't a function. A context consumer expects a single child that is a function. If you did pass a function, make sure there is no trailing or leading whitespace around it
2.Rendering directly is not supported and will be removed in a future major release. Did you mean to render <Context.Consumer> instead?
3.render2 is not a function
what to do ?
Below is my app structure :
<CitiesProvider>
<BrowserRouter>
<Routes>
<Route path="/" element={<Homepage />} />
<Route path="product" element={<Product />} />
<Route path="pricing" element={<Pricing />} />
<Route path="login" element={<Login />} />
<Route path="*" element={<NotFound />} />
<Route path="app" element={<AppLayout />}>
<Route index element={<Navigate replace to="cities" />} />
<Route path="cities" element={<CityList />} />
<Route path="countries" element={<CountryList />} />
<Route path="cities/:id" element={<City />} />
<Route path="form" element={<Form />} />
</Route>
</Routes>
</BrowserRouter>
</CitiesProvider>
I am using react leaflet in my react app. I used context api to build my project. But when i tried using the leaflet using code :
<MapContainer center={position} zoom={13} scrollWheelZoom={false}>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={position}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
I get errors like :
1.A context consumer was rendered with multiple children, or a child that isn't a function. A context consumer expects a single child that is a function. If you did pass a function, make sure there is no trailing or leading whitespace around it
2.Rendering directly is not supported and will be removed in a future major release. Did you mean to render <Context.Consumer> instead?
3.render2 is not a function
what to do ?
Below is my app structure :
<CitiesProvider>
<BrowserRouter>
<Routes>
<Route path="/" element={<Homepage />} />
<Route path="product" element={<Product />} />
<Route path="pricing" element={<Pricing />} />
<Route path="login" element={<Login />} />
<Route path="*" element={<NotFound />} />
<Route path="app" element={<AppLayout />}>
<Route index element={<Navigate replace to="cities" />} />
<Route path="cities" element={<CityList />} />
<Route path="countries" element={<CountryList />} />
<Route path="cities/:id" element={<City />} />
<Route path="form" element={<Form />} />
</Route>
</Routes>
</BrowserRouter>
</CitiesProvider>
Share
Improve this question
asked yesterday
Aditya NagareAditya Nagare
1471 silver badge10 bronze badges
2 Answers
Reset to default 1I was running into the same thing and the version I installed was v5.0.0
I downgraded to v4.2.1 and it is rendering now. I have an older version of react so I'm wondering if this had something to do with it, but I'm thinking this could help you as well.
Make sure CitiesProvider only wraps a single child node. Currently, it may be trying to render multiple components, causing errors. Use React.Fragment or a single component to wrap, you can try:
<CitiesProvider>
<>
<BrowserRouter>
<Routes>
<Route path="/" element={<Homepage />} />
<Route path="product" element={<Product />} />
<Route path="pricing" element={<Pricing />} />
<Route path="login" element={<Login />} />
<Route path="*" element={<NotFound />} />
<Route path="app" element={<AppLayout />}>
<Route index element={<Navigate replace to="cities" />} />
<Route path="cities" element={<CityList />} />
<Route path="countries" element={<CountryList />} />
<Route path="cities/:id" element={<City />} />
<Route path="form" element={<Form />} />
</Route>
</Routes>
</BrowserRouter>
</>
</CitiesProvider>
本文标签:
版权声明:本文标题:reactjs - Rendering <Context> directly is not supported and will be removed in a future major release. Did you mea 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283164a1926877.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论