Giter Club home page Giter Club logo

Comments (8)

redanium avatar redanium commented on May 18, 2024

Use it in both processes with require('electron-config') assuming you are using the default name( config.json) but in the main process it has to be after you set the userData path.

//Main process
...
const Config = require('electron-config');
...
app.setPath("userData", __dirname + "/userData");
const config = new Config();
config.set('xxx','yyy')
...

I hope this will help :)

from electron-store.

naheller avatar naheller commented on May 18, 2024

This helps, but there is an issue using "require" in React components. Could you give an example of how to use electron-config in a React renderer process?

from electron-store.

redanium avatar redanium commented on May 18, 2024

refer to this Developing desktop applications with Electron and React

from electron-store.

sindresorhus avatar sindresorhus commented on May 18, 2024

How do I use electron-config with my React component and send the user data over to the main Electron process?

You don't. As mentioned in the readme, it works in both the main and renderer process, so you just use it exactly as you would have in the main process. The IPC stuff is handled for you.

from electron-store.

naheller avatar naheller commented on May 18, 2024

I have a general understanding of using React and Electron -- I just need a little guidance on the specific syntax of calling up electron-config in a React component.

from electron-store.

sindresorhus avatar sindresorhus commented on May 18, 2024

See the usage example: https://github.com/sindresorhus/electron-config#usage You require it, initialize it, and then, for example, call config.get('savedConfigItem') in a React component when you need that info. If you have a lot of defaults, it can be smart to put it in a separate file so it can be easily required in multiple files: https://github.com/sindresorhus/caprine/blob/6269a983be6e8cafad2a4ab27448fdacb83c9755/config.js

from electron-store.

 avatar commented on May 18, 2024

See the usage example: https://github.com/sindresorhus/electron-config#usage You require it, initialize it, and then, for example, call config.get('savedConfigItem') in a React component when you need that info. If you have a lot of defaults, it can be smart to put it in a separate file so it can be easily required in multiple files: https://github.com/sindresorhus/caprine/blob/6269a983be6e8cafad2a4ab27448fdacb83c9755/config.js

i required and initialized the store in the main process. Now if i want to use it in renderer, (react in my case) how do i import that store or do i create a new store?

from electron-store.

sindresorhus avatar sindresorhus commented on May 18, 2024

See #15

from electron-store.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.