Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More detail on usage in Main vs Renderer processes #10

Closed
naheller opened this issue May 9, 2017 · 8 comments
Closed

More detail on usage in Main vs Renderer processes #10

naheller opened this issue May 9, 2017 · 8 comments

Comments

@naheller
Copy link

naheller commented May 9, 2017

I am using Electron and React to create a web app, and the documentation for electron-config does not show how to carry out IPC (inter-process communication) between processes.

In the case of React, the render process would be a component. How do I use electron-config with my React component and send the user data over to the main Electron process?

Thanks

@redanium
Copy link

redanium commented May 9, 2017

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 :)

@naheller
Copy link
Author

naheller commented May 9, 2017

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?

@redanium
Copy link

redanium commented May 9, 2017

@sindresorhus
Copy link
Owner

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.

@naheller
Copy link
Author

naheller commented May 9, 2017

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.

@sindresorhus
Copy link
Owner

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

@ghost
Copy link

ghost commented Aug 15, 2019

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?

@sindresorhus
Copy link
Owner

See #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants