score:0
Accepted answer
i was not able to find perfect solution but workaround mentioned below was good enough for me to achieve what i was looking for.
i have created common table headers index file which contains all locations for table headers:
tableheaders.jsx
let tablelheaders = {};
tableheaders['propa'] = require('../tablea/tableaheaders.jsx').default;
tableheaders['propb'] = require('../tableb/tablebheaders.jsx').default;
tableheaders['propc'] = require('../tableb/tablecheaders.jsx').default;
...
tableheaders['propx'] = require('../tablex/tablexheaders.jsx').default;
export default tableheaders
and then in the view for the main component specify prop for that:
<mytable tableheaders="propa" />
and in the mytable
component access it as require
instead of import
mytable.jsx:
import tableheaders from "tableheaders.jsx;
....
const tablecolumns = tablelheaders[props.tableheaders];
hope it will helps someone else or somebody else will came up with better solution.
Source: stackoverflow.com
Related Query
- Import component based on passed prop
- Infer type of props based on component passed also as prop
- How can I display React component based on prop name passed into a container?
- React - How to pass props to a component passed as prop
- How to spyOn method inside prop passed down to a component using Jest?
- Conditionally inline style a react component based on prop
- React Hooks - function inside function component passed as prop can't access state
- Render a Component passed in as a Prop
- Apollo: data / mutation prop not passed to component
- How to access a prop in a layout component if my component is being passed to the layout component as a chilren prop in ReactJS?
- How to type async function passed as prop to React component
- Reducer function passed to useReducer hook is executed multiple times for one dispatch call when reducer function is dependant on a component prop
- Dynamically import component in React based on config entries
- Prop passed to child component does not change its value in child upon updating prop in parent
- How to make prop mandatory based on another prop being passed
- Create type for component based on props passed
- Adding some bold text inside a text string passed as a prop to a component
- How to load react component based on prop value
- How to unit test React functions passed in as prop to child component with Enzyme shallow wrapper
- Styled Component - How to prevent a prop from being passed to the extended component?
- React: Unable to access the parent component's function which is passed as prop to child component
- How can I dynamically create a component based on a prop or variable using React.createElement
- React - passing component prop in click handlers passed as props
- react function undefined when passed to functional component as a prop
- How to handle state in useEffect from a prop passed from infinite scroll component
- React hooks. Update component passed as param via onClick after one of it's prop was changed
- How to access the passed prop array inside the child component
- Adding additional props to a component passed as a prop
- typescript correct type for svg component passed as prop
- React.js : Rendering the same component differently based on the id passed
More Query from same tag
- 'Unexpected token, expected ")"' on catch block when adding Typescript to ReactJS project?
- How can I make a text input non editable with React?
- How can I mutate my state without having to reload the entire json object via the API
- React - useMemo has a complex expression - Extract it to a separate variable so it can be statically checked
- can we deploy an react js application without source(src folder) code locally
- React conditionally render a component in specific routes
- How to Change the Color of the typography with a certain condition
- After GraphQL Query: Property 'then' does not exist on type 'void'
- clear state of redux when navigating to different route
- How can I loop through a list of on react?
- typescript overload mui interface, type is not assignable
- Dependency Injection in Stateless function is ok, but how do it in normal React Component
- How to set nginx to serve React and Django properly
- Currently refactoring my Firestore post data function into an array storage
- getInitialProps does not work with async function
- Why is my onClick event not triggering on React?
- axios doesnt post data to server
- Attempted import error: 'AiFillMessage' is not exported from 'react-icons/fa' (imported as 'MessengerIcon')
- React Cursor jumping when formatting textfield
- With React Router : How to render a component multiple times with differents props each time in a Route?
- fetching data from graphql to react
- How to change Redux state from a path string?
- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'type') redux reactjs
- For empty object giving the TypeError: Cannot convert undefined or null to object
- Why is my function not working everytime I open the screen?
- ReactJS: How to create a transparent page?
- ReactJS server-side rendering vs client-side rendering
- How does React.useState triggers re-render?
- How to find scope of React function?
- how do i create a new object based off an array and another object?