propTypes warning in Electron app

2019-03-06 15:34发布

问题:

I am trying to deal with the new warning about needing to include the prop-types package in NPM programs. My app is an electron app.

I think I am following the migration strategy from the React folks: https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html

react version-15.4.2, prop-types version 15.5.8, react-dom 15.42.2

However, I am still getting the warning after adding the prop-types package.

This is the component (Dashboard.jsx)

const React = require('react')
const { Component } = require('react')
const {} = require('react-bootstrap')
import PropTypes from 'prop-types'
import { App, Title, Section, Header, Footer, Columns, Box, Button } from 'grommet'


export const Page = props => (
  <App>
    <Title>Dashboard Version 1.0, Node version: xxx</Title>
    <Section>Status Section
      <p>Status: {props.serverState}</p>
    </Section>
    <Section >{/*  colorIndex='neutral-1' */ }
      <Header>Controls</Header>
      <Columns>
        <Box pad='small'>
        <Button label='Install' onClick={props.installAct}></Button>
        </Box>
        <Box pad='small'>
        <Button label='UnInstall' onClick={props.uninstallAct}></Button>
        </Box>
        <Box pad='small'>
        <Button label='Start' onClick={props.startAct}></Button>
        </Box>
        <Box pad='small'>
        <Button label='Stop' onClick={props.stopAct}></Button>
        </Box>
      </Columns>
    </Section>
    <Section>
      <Header>Config</Header>
    </Section>
    <Section>
      <Header>Cleanup</Header>
    </Section>
    <Footer></Footer>
  </App>
)

And this is the main render process (dash.js)

const { ipcRenderer, remote } = require('electron')
const { createStore } = require('redux')
const { composeWithDevTools } = require('redux-devtools-extension')
const { Page } = require('../jsxo/Dashboard.js')
const React = require('react');
const ReactDOM = require('react-dom')
const PropTypes = require('prop-types')
const Immutable = require('immutable')

document.addEventListener("DOMContentLoaded", render)



const page = React.createElement(Page, { serverState: 'UP', 
        installAct: () => alert('install'),
        uninstallAct: () => alert('uninstall'),
        startAct: () => alert('start'),
        stopAct: () => alert('stop') })


function render() {
    ReactDOM.render(page, document.getElementById('page'))
}

回答1:

You are using grommet which hasn't been updated to the new react version yet, therefore you will be getting warnings from this library because it uses the deprecated PropTypes from react module.

There is nothing you can do until your dependencies are updated, too.

Note this has been already reported and there is a pull request open.



标签: reactjs redux