Socket
Socket
Sign inDemoInstall

electron-only

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-only

React component for rendering component for Electron based clients only


Version published
Weekly downloads
7
increased by40%
Maintainers
1
Weekly downloads
 
Created
Source

react-for-electron-only

build status Coverage Status PRs Welcome npm version NPM

React component for rendering component for Electron based clients only. <ForElectronOnly> would render children in case when react application runs in Electron Desktop client, else would render nothing(null) .

Use Cases

Trivial Case

Considering any isomorphic app which is distributed on ElectronJS and also over Web with same react codebase, say for eg. slack (which renders same UI on electron desktop client and web), there are use cases when you want to render particular DOM node/components on Electron Only and not on browser or vice versa.

Exclusive Functionality

There are set of APIs from electron that would give native UI feel eg, dialog module. For instance, one may have folder/file path as input text on browser while on electron one may use dialog.showOpenDialog functionality via a button. Use of such APIs also eliminate some validation errors.

Install

$ npm install electron-only --save

or

yarn add electron-only

Example

  1. <ForElectronOnly>

    import ForElectronOnly from 'electron-only';
    
    ...
    render(){
        return (
            <ForElectronOnly>
                <div className="electron-ui">
                    This will only get rendered on Electron
                </div>
            </ForElectronOnly>
        )
    }
    ...
    

    This is render div.electron-ui on electron and nothing on normal browsers.

  2. <ForElectronOnly> with fallbackComponent option

    import ForElectronOnly from 'electron-only';
    
    ...
    render(){
        return (
            <ForElectronOnly
            fallbackComponent={<div className="browser-ui"> This will only get rendered in Browser </div>}>
                <div className="electron-ui">
                    This will only get rendered on Electron
                </div>
            </ForElectronOnly>
        )
    }
    ...
    

    This is render div.electron-ui on electron and div.browser-ui on browser.

  3. ForNonElectronOnly (supports fallbackComponent prop)

    import {ForNonElectronOnly} from 'electron-only';
    
    ...
    render(){
        return (
            <ForNonElectronOnly
            fallbackComponent={<div className="electron-ui"> This will only get rendered in Electron </div>}>
                <div className="browser-ui">
                    This will only get rendered on Browser
                </div>
            </ForNonElectronOnly>
        )
    }
    ...
    

    ForNonElectronOnly is exactly opposite of ForElectronOnly, ie, it will render div.electron-ui on electron and div.browser-ui on browser.

APIs

ForElectronOnly Component

Import mechanism
import ForElectronOnly from 'electron-only'
Properties
proptypedescriptiondefault value
children (default)nodeComponent to be render for electronnull
fallbackComponentnodeComponent/Node to be rendered for browsernull

ForNonElectronOnly Component

Import mechanism
import {ForNonElectronOnly} from 'electron-only'
Properties
proptypedescriptiondefault value
children (default)nodeComponent to be render for browsernull
fallbackComponentnodeComponent/Node to be rendered for electronnull

isElectron function

Import mechanism
import {isElectron} from 'electron-only'
//or import ElectronOnly from 'electron-only';
// and then ElectronOnly.isElectron function can be used
Return values
valuedescriptioncomment
trueif code is executed on Electron
falseif code is not executed on Electronimplies both browser and server execution

License

Open Source Love

refer LICENSE file in this repository.

Keywords

FAQs

Package last updated on 03 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc