小编dem*_*ist的帖子

react-router v4 - browserHistory未定义

我正在创建我的第一个电子反应应用程序(我的第一个电子应用程序).我有两条路线需要从一条路线导航到另一条路线.为此,我使用以下代码:

ReactDOM.render(
  <Router history={browserHistory}>
      <App />
  </Router>,
  document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)

应用

class App extends React.Component {
    constructor() {
        super();
    }
    render() {
        return (
            <div className="app-master">
                <Switch>
                    <Route path='/city' component={CityList}/>
                    <Route path='/' component={SplashScreen}/>
                </Switch>
            </div>
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

import { browserHistory } from 'react-router';
...
browserHistory.push('/city');
Run Code Online (Sandbox Code Playgroud)

这条线给出错误,

TypeError: Cannot read property 'push' of undefined
Run Code Online (Sandbox Code Playgroud)

我在网上搜索可能的解决方案,但找不到一个!关于SO也有很多类似的问题,但没有一个对我有用:(

javascript reactjs react-router electron

16
推荐指数
1
解决办法
3万
查看次数

如果组件道具类型无效,如何防止构建应用程序?

以下是PropTypes的示例:

import PropTypes from 'prop-types';

class Greeting extends React.Component {
  render() {
    return (
      <h1>Hello, {this.props.name}</h1>
    );
  }
}

Greeting.propTypes = {
  name: PropTypes.string
};
Run Code Online (Sandbox Code Playgroud)

现在我使用Greeting组件:

<Greetings otherProp="this is a invalid prop" />
Run Code Online (Sandbox Code Playgroud)

在这种情况下,当我构建应用程序以进行部署时,不会抛出任何错误并成功构建应用程序.但它会在运行时出错并发生故障.

如何添加检查以消除此问题并确保没有使用错误的prop类型构建组件.

javascript reactjs react-proptypes

14
推荐指数
1
解决办法
544
查看次数

如何在 google-protobufjs 中设置枚举值

您好,有一个 proto 文件,如下所示:

enum Type
{
    A = 0;
    B = 1;
    C = 2;
}

message Message
{
    User to = 1;
    User from = 2;
    Type type = 3;
}
Run Code Online (Sandbox Code Playgroud)

我使用protoc编译器将其转换为 javascript 实用程序类。使用这个生成的 javascript 文件,我在我的应用程序中设置了 Message 对象,如下所示:

const message = new Main.Message()
message.setTo(this.user1) // saved user
message.setFrom(this.user3) // saved user
message.setType(0) // trying to set type to A

const buffer = message.serializeBinary()
socket.send(buffer)
Run Code Online (Sandbox Code Playgroud)

我面临的问题是消息对象tofrom字段都得到了正确更新,但type仍然存在null!我无法为此找到解决方案。

这是因为在Messageproto 中,预期类型是 …

javascript protocol-buffers

7
推荐指数
1
解决办法
4789
查看次数

更新到Xcode 5.1后,iOS 7.1会出错

我最近将我的Xcode更新到了5.1版.更新后,它可以在除iOS 7.1之外的所有模拟器上正常运行,其中会出现mach-O链接错误.此外,"构建设置"选项卡中只有64位架构选项.据我所知,这是所有问题和错误的原因.有谁知道这个的原因以及如何解决它?

以下是我收到的一些警告和错误:

警告 :

Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead
Run Code Online (Sandbox Code Playgroud)

错误:

Symbol(s) not found for architecture x86_64
Run Code Online (Sandbox Code Playgroud)

谢谢.

iphone ios arm64 ios7.1 xcode5.1

5
推荐指数
2
解决办法
6410
查看次数

限制 div 中的单词数

是否有css属性可以限制div中显示的字符数。例如

<div class ="main-text">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, …
Run Code Online (Sandbox Code Playgroud)

html css wordpress

4
推荐指数
2
解决办法
2万
查看次数

避免React setState()回调循环

我试图同时设置多个状态属性,但由于我setState()异步的,我将使用回调,但作为更多的属性,我必须一次编辑这个代码变得越来越难看!

有没有其他好方法来实现这一目标?

this.setState(
  {
    item_1: true
  },
  (e => {
    this.setState(
      {
        item_2: false
      },
      (e => {
        this.setState(
          {
            item_3: 'Hello World'
          }
        )
      })
    )
  })
)
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

1
推荐指数
1
解决办法
348
查看次数