I am trying to render the React components dynamically based on the routes that are given in the URL.
canvas/index.tsx
export { default as CardGroup } from "./cards.example";
src/App.tsx
import React from "react";
import {
useParams
} from "react-router-dom";
import * as Canvas from "./canvas";
const App: React.FC = () => {
const params = useParams();
const widgetName = (params.widgetName ?? '';
return (
<div className = "App" >
{< Canvas[widgetName] / >} // error here
</div>
);
};
export default App;
I am not able to render the widget. It give me the following error.
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import("/Users/mypc/Code/atoms/src/canvas/index")'.
No index signature with a parameter of type 'string' was found on type 'typeof import("/Users/mypc/Code/atoms/src/canvas/index")'.
