Blog>
Snippets

Initializing TanStack Config in a React Project

Demonstrate the initialization and basic setup of TanStack Config in a React application, including how to create a default configuration.
npm install @tanstack/config-core
First, install TanStack Config by running this command in your project's terminal. This adds the necessary library to your project.
// tanstack-config.js
export default {
  apiBaseUrl: 'https://api.example.com',
  enableLogging: true,
  theme: 'dark',
};
Create a tanstack-config.js file at the root of your project. This file exports a default object containing your application's configuration settings, such as API base URL, logging preference, and a theme.
import config from './tanstack-config';
console.log(config.apiBaseUrl); // Usage example
In your React application, import the configuration from tanstack-config.js to utilize the settings throughout your application. This example demonstrates accessing the API base URL from the config.