小编sho*_*ode的帖子

this.props.history.push不重新渲染React组件

在我的组件中,我使用this.props.history.push(pathname:.. search:..)重新渲染组件并从第三方服务获取新数据。当我第一次调用该页面时,它将呈现。但是,当我在组件内部调用历史记录推送时,URL会正确更新,但组件不会重新呈现。我读了很多书,但无法正常工作。有任何想法吗?

我正在使用React Router V4

//index.js

  <Provider store={store}>
    <BrowserRouter>
      <Switch>
        <Route path="/login" component={Login}/>
        <Route path="/" component={Main}/>
      </Switch>
    </BrowserRouter>
  </Provider>


//Main.js
//PropsRoute is used to push props to logs component so I can use them when fetching new data
const PropsRoute = ({ component: Component, ...rest }) => {
  return (
    <Route {...rest} render={props => <Component {...props} />}/>
  );
};

class Main extends Component {
  render() {
    return (
        <div className="app">
          <NavigationBar/>
          <div className="app-body">
            <SideBar/>
            <Switch>
              <PropsRoute path="/logs" component={Log}/> //this component …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router react-router-v4

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

反应原生 ios 构建成功但应用程序包的路径错误

当我运行 react-native run-ios build 成功并在 ios 下创建了 build 文件夹。但是在构建后,当安装开始时,出现以下错误。当我通过 xcode 运行该项目时,该项目成功运行。我观察到的是,以“DerivedData”开头的路径是错误的。相反,它应该是“构建”。当我将我的“build”文件夹重命名为“DerivedData”并重新运行“react-native run-ios”时,整个过程成功完成,当然还有之前的构建。

如何将“DerivedData”更改为“build”?

我从 0.59.9 升级到 0.60.0 后立即出现此错误。

错误: info 安装“DerivedData/Build/Products/Debug-iphonesimulator/mobileappname.app” 处理命令时遇到错误(域=NSPOSIXErrorDomain,代码=2):无法安装请求的应用程序 在提供的路径中找不到应用程序包. 提供所需应用程序包的有效路径。打印:条目,“:CFBundleIdentifier”,不存在错误命令失败:/usr/libexec/PlistBuddy -c 打印:CFBundleIdentifier DerivedData/Build/Products/Debug-iphonesimulator/mobileappname.app/Info.plist 打印:条目,“: CFBundleIdentifier”,不存在。使用 --verbose 标志运行 CLI 以获取更多详细信息。错误:命令失败:/usr/libexec/PlistBuddy -c Print:CFBundleIdentifier DerivedData/Build/Products/Debug-iphonesimulator/mobileappname.app/Info.plist Print: Entry, ":

在 checkExecSyncError (child_process.js:616:11) at Object.execFileSync (child_process.js:634:13) at runOnSimulator (/Users/armaneker/WebstormProjects/mobileappname/node_modules/@react-native-community/cli-platform-ios /build/commands/runIOS/index.js:189:45) 在 process._tickCallback (internal/process/next_tick.js:68:7)

React Native 版本: 系统:操作系统:macOS 10.15 二进制文件:节点:10.15.3 - /usr/local/bin/node npm:6.13.1 - /usr/local/bin/npm Watchman:4.9.0 - /usr/local /bin/watchman SDKs: iOS SDK: 平台: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS …

ios reactjs react-native

6
推荐指数
2
解决办法
4095
查看次数

Reactjs - 在 api 调用失败时注销/重定向用户

我使用 Reactjs 构建了一个 Web 应用程序。我使用路由器和 redux 进行状态管理进行身份验证。一切正常,但问题出在 api 调用上。用户登录并调用 ... 服务后,我想检查服务的响应是否包含任何令牌问题(例如:令牌已过期)。如果存在令牌问题,我想使令牌无效(将其删除)并将用户发送回带有错误消息的登录页面。现在,如果我在 redux action/reducer 中执行所有 api 调用,我就可以做到这一点。但是我不确定是否必须为每次调用都实现 redux,因为我不需要其他组件中的数据。而且在 redux 中实现所有服务非常耗时并且需要大量代码。

我将该项目复制到 stackblitz。

https://stackblitz.com/edit/react-auth?file=index.js

场景很简单。单击登录,您就在应用程序中。该应用程序会自动调用服务并获得响应。如果您在 api.js 中将 URL 更改为错误的 URL,则此服务将提供“40x”响应。当我收到此响应时,我想将用户重定向到登录页面。

任何帮助/建议?

谢谢。

reactjs react-router redux react-redux

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

Polymer 3 lit-element:请求渲染未拾取数组对象更改

我有一个对象如下。现在,当我更改属性并调用 requestRender 时,它不会触发。据我所知,未检测到属性更改。我怎样才能做到这一点?

static get properties() {
  return {
    items: Object
    }
}

constructor() {
  super();
  this.items = {
    list: [{ a: 5, b: 6 },{ a: 5, b: 6 }]
  }
}

onClick() {
  this.items.list[1].a = 10; //change property
  requestRender(); //doesn't pick up the change...
}
Run Code Online (Sandbox Code Playgroud)

javascript polymer polymer-3.x lit-element

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