score:0
you cannot instantiate a react element directly from a string, you will have to maintain a mapping from strings to react classes.
const map = { "componenta" : componenta }
// render
<map[match.params.topicid] />
score:0
if you have a component for each case of match.params.topicid
you can build a dictionary that maps the values of topicid
to their respective component.
for example, if you have two possible values for topicid
that are topicid1 (associated to topicid1
component) and topicid2 (associated to topicid2
component) you could render your component with the following code:
const topicsmap = {
topicid1: topicid1,
topicid2: topicid2
};
const topic = ({ match }) => {
const topicid = topicsmap[match.params.topicid] || topiciddefault;
return (
<div>
<h3>{match.params.topicid}</h3>
<topicid />
<companydashboardmain/>
<companyaccdetailsmain/>
</div>
);
};
note that i am defining a default component topiciddefault
just in case the match.params.topicid
does not match any of the expected values (topicid1 and topicid2).
Source: stackoverflow.com
Related Query
- Using React Router DOM Route in Material-UI Breadcrumbs
- Is it possible to create nested routes with multiple levels using react router dom
- Dynamic breadcrumbs using react router
- ReactJS - Handle POST requests using react router dom
- Using render in react router dom with a private route
- Using condition for redirecting in react router dom v6
- Show Sidebar Navigation only at Home using React Router Dom
- ReactJS -How to create multistep component/form with single path using React Router
- how to get params using react router dom v5.0.1
- how to show details page using react router dom
- Scroll to a specific div on a new page using react router dom
- How to create list and detail view using React Router DOM?
- Convert from react router dom v5 to react router dom v6 when using useRouteMatch
- Get id using useParams hook in functional component - react router dom v6
- can't pass props using Link in react router dom
- Exclude a route for production using React Router within Create React App
- Authorization and Authentication using react - router - dom
- Functions are not valid as react child Error while using Navigate in react router dom
- form using React hook form and redux toolkit. then routes in react router dom
- External link not working when using LINK from react router dom
- React Router Dom & Firebase Auth: history.push changes url but does not render new component when called after firebase auth create account
- how to navigate submenu items using React Router Dom v6
- How to create admin route using react router v 6
- How to nest routes using react router dom
- how to acces url in data using useParam in react router dom
- Redirect not working on React, using react router dom
- React, getting Uncaught TypeError: Cannot read properties of null (reading "useRef") while using React Router Dom
- How to render an iframe of local page within React app using React Router Dom
- How to run use effect in App.js while using react router dom
- Display URL params on page when using react `withRouter` from react router dom
More Query from same tag
- How to load and play a Youtube video in React
- Programmatically triggering a click
- Material-ui overwrite components gutter breakpoint styles TypeError: Cannot read property 'breakpoints' of undefined
- Api fetch - Cannot read property 'json' of undefined
- Problem with local server, starting react app
- How to Remove Active Background in React-Bootstrap
- "java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema" when accepting SDK licenses
- React JS - How to add value from state to specific element
- Next.js handle 0Auth authorization with MoneyButton
- React redux search is not working properly
- ReactDOMServer is not defined
- POST not finishing before .then() runs in async call
- Is it possible to show a caps lock indicator on a password field in formik?
- Authentication credentials were not provided when sending request from React JS axios
- reflection to pass tagName as string props to be rendered
- How to set component state conditionally
- React - API Call returning correct result but not passing along
- How can you conditionally tell TypeScript which data type to use?
- How to detect when ReactJS has finished page manipulation?
- How to use Material UI's 'useMediaQuery' with a class component
- Javascript ajax library supporting global events
- Reset form method not working in timepicker
- When I try to change one state of an object the other also changes (React)
- Is there a way to destructure an object into a new object in es6?
- Map nested JSON object in React
- React child component's state is undefined
- Roving tabindex w/ React
- React - Set input number value conditionally
- How to detect disconnect and reconnect for subscription(websocket) in apollo client
- Why do React components that throw errors render twice?