score:1
Accepted answer
it's a good idea and commonly used for configs:
src |
config |
config1.js
config2.js
index.js
you define a config file as .json
or equivialent javascript object
:
const config = {
sitetitle: '...',
sitedescription: '...',
sitekeywords: '...',
siteurl: '...',
sitelanguage: '...',
googleanalyticsid: '...',
googleverification: '...',
name: '...',
location: '...',
githublink: '...'
navlinks: [
{
name: 'about',
url: '#about',
},
{
name: 'timeline',
url: '#jobs',
},
{
name: 'projects',
url: '#projects',
},
{
name: 'contact',
url: '#contact',
},
]
};
export default config;
and use it across components:
import { githublink, navlinks } from '@config';
Source: stackoverflow.com
Related Query
- React - Use JSON to store data
- Store fetch data in a variable and use entire json as a prop in a react component
- How to use rendered json data in React component
- Use specific elements from JSON data and display it on a React page?
- How necessary is it to use Redux in React and store data locally if you're using Firebase and its active listeners?
- I have been trying to use Fetch to get data from an external json file with react but kept getting errors
- Error: Objects are not valid as a React child. If you meant to render a collection of children, use an array instead. Getting data from JSON
- I do not know how to store json data from an api call within a nodejs express server, and send it to a react native client
- Data from one JSON file is overwriting another JSON dataset when trying to use react-select module in a form in React
- How can I import and use data from a JSON file in my React app?
- Fetching JSON data array, how to use it with React Bootstrap Table?
- Preparing JSON data into a JavaScript array to use in react-heatmap-grid React app
- how to import json data file and use it in a react component?
- loading json data from local file into React JS
- React + Flux - should store data be stored in a component state, or props?
- How do I use local state along with redux store state in the same react component?
- How to store data locally in React Native that is not a string
- React JS animations based on JSON data
- React Native - Return all JSON data in AsyncStorage?
- How to parse json data in react native
- how to import data in react from a js file to use in components
- How to fetch data and store in React Context API?
- React - load all data from json into component
- Rendering React components from json data dynamically
- MobX - Why should I use `observer` when I could use `inject` when injecting data into a React component
- Using fetch to render json data in react app
- React JS - How do I bind json data to a dropdown list
- react use dangerouslySetInnerHTML to render json with html tags
- is it safe to use react js state to store token of authenticated user?
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
More Query from same tag
- How to navigate other screen using react navigation 5
- How to delete object from array?
- Rendering an error message after form submission in React
- why role base parent of two child component have different state if update in one of these child component in reactjs
- using analytics.js and react-ga
- React - only one "active" child component at any one time
- React component render is called multiple times when pushing new URL
- Solve having more than one copy of React in the same app
- React hooks component not updating after map, but see data loading / refreshing with error
- Is it possible to restrict to multiple roles in react-admin?
- Configure Webpack to serve react at relative path
- React TypeScript 16.8 How to make useEffect() async
- How modify API request?
- Table with row scope in html does not work
- Clicking on file input in a react-bootstrap Dropdown does not open the borwser's Open file dialog
- Unhandled Rejection (TypeError): Object(...) is not a function
- Pass children tags as props to components in Functions
- Redux actions callback
- React Apollo data directly to React Context
- How to format date in React material-ui date-picker?
- Loading Images In reactjs using nodejs
- How to get the path to a file outside the root folder in React application
- Do I need use inheritance for react components?
- Caching images in browser with URL parameters and XSendFile
- How to paginate in react using inertia on laravel?
- NextJS 9.3 Link not a constructor function for JSX elements
- Is it a good practice to use React useEffect as listener to trigger action?
- TypeError: Cannot read properties of undefined (reading 'MethodInfo') in react js app using grpc-web
- How to pass props down to child component in React
- Persisting state on browser reload not working in react