小编dre*_*val的帖子

找不到Vue命令

尝试安装Vue但我收到错误-bash:vue:command not found.请看截图.根据Vue说明安装了所有内容,但我仍然收到此错误.请帮忙.谢谢

错误的屏幕截图

node.js npm vue.js vue-cli

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

使用钩子响应上下文可防止重新渲染

我使用带有钩子的 React 上下文作为我的 React 应用程序的状态管理器。每次 store 中的值发生变化时,所有组件都会重新渲染。

有没有办法阻止 React 组件重新渲染?

店铺配置:

import React, { useReducer } from "react";
import rootReducer from "./reducers/rootReducer";

export const ApiContext = React.createContext();

export const Provider = ({ children }) => {
  const [state, dispatch] = useReducer(rootReducer, {});

  return (
    <ApiContext.Provider value={{ ...state, dispatch }}>
      {children}
    </ApiContext.Provider>
  );
};
Run Code Online (Sandbox Code Playgroud)

减速器的一个例子:

import * as types from "./../actionTypes";

const initialState = {
  fetchedBooks: null
};

const bookReducer = (state = initialState, action) => {
  switch (action.type) {
    case …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native react-context

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

React Typescript:'{ [x: number]: any; 类型的参数 }' 不能分配给类型的参数

我在我的项目(React、TS、Mobx)中添加了 onChange 方法,但出现错误: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type

我是 TypeScript 的新手,不知道为什么会这样。可能是什么问题?

(parameter) event: {
    target: {
        name: any;
        value: any;
    };
}
Run Code Online (Sandbox Code Playgroud)

'{ [x: number]: any; 类型的参数 }' 不可分配给类型为 'IAddPlayerFormState | 的参数 ((prevState: Readonly, props: Readonly) => IAddPlayerFormState | Pick | null) | 选择<...> | 空值'。

在此处输入图片说明

import React, { Component } from 'react';
import ViewStore from '../../../store/ViewStore';
import { TextField } from './../../../utils';

interface IAddPlayerFormProps {
  viewStore?: ViewStore; // Optional …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs mobx

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

Firebase crashlytics 自动上传 dsym

我正在使用 React Native Firebase。在 firebase crashlytics 中,我缺少 DSYM。 在此输入图像描述

在每个构建中自动添加 dSYM 的正确方法是什么?我想应该将其添加到运行脚本中?/path/to/pods/directory/FirebaseCrashlytics/upload-symbols如果是这样,我怎样才能获得和 的路径/path/to/dSYMs

谢谢!

ios firebase crashlytics react-native

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

React Navigation header onPress - this.setState 不是函数

我在我的项目中使用 react-navigation,我需要在右标题按钮单击时切换模式。当我 setState 为 true 时,我得到未定义。

代码:

import React, { Component } from 'react';
import { View, Text } from 'react-native';
import { ToggleDrawer, ToggleAdditional } from '../../utils';
import { AdditionalModal } from '../../components';

class Settings extends Component {
  static navigationOptions = ({ navigation }) => {
    const { params = {} } = navigation.state;
    return {
      headerTitle: 'Profile',
      headerLeft: <ToggleDrawer pressHandler={() => navigation.openDrawer()} />,
      headerRight: (
        <ToggleAdditional pressHandler={() => params.handleAdditionalModal()} />
      )
    };
  };

  constructor(props) {
    super(props);

    this.state = …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

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

ESLint:在引用前一个状态时在 setState 中使用回调

对于这段代码,我收到 eslint(AirBnb config) 错误:引用前一个状态时在 setState 中使用回调

此错误是否会以某种方式影响性能以及如何解决?

  handleSelect(event) {
    const entry = event.nativeEvent;

    if (entry == null) {
      this.setState({ ...this.state, selectedEntry: entry });
    } else
      this.setState({
        ...this.state,
        selectedEntry: JSON.stringify(entry),
        markerIsEnabled: true
      });

    console.log(event.nativeEvent);
  }
Run Code Online (Sandbox Code Playgroud)

javascript reactjs eslint

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

React Formik-仅在表单提交时触发验证

我在React Native应用程序中使用Formik。在登录表单上,我有两个字段:电子邮件和密码,这两个字段都是必需的。

我已经写了这样的验证规则:

export const LoginSchema = Yup.object().shape({
  email: Yup.string()
    .email('The email is invalid')
    .required('This field is required'),
  password: Yup.string()
    .min(6, 'The password is too short')
    .max(12, 'The password is too long')
    .required('This field is required'),
});
Run Code Online (Sandbox Code Playgroud)

我只需要在表单提交时触发验证并显示错误弹出窗口。我已经阅读了文档,但是找不到解决方案,因为验证会触发onBlur。如何才能做到这一点?

谢谢!

const Login = ({ navigation }) => {
  const [isLoading, setIsLoading] = useState(true);
  const [isVisible, setIsVisible] = useState(false);

  useEffect(() => {
    // Later check for token
    const tokenIsStored = true;

    if (tokenIsStored) {
      setIsLoading(false);
    }
  });

  const onLogin = values => …
Run Code Online (Sandbox Code Playgroud)

validation reactjs react-native yup formik

4
推荐指数
3
解决办法
2605
查看次数

React Native:使用 npm 命令生成发布版 APK

我正在使用这样的命令来生成一个 APK:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-android
Run Code Online (Sandbox Code Playgroud)

是否可以编辑此命令以生成发布版 APK?

android react-native

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

React Hooks Mobx:无效的钩子调用。Hooks 只能在函数组件内部调用

我正在使用 React Hooks,当我用来自 mobx 的观察者包装我的组件时,我收到了这个错误。可能是什么问题?是否可以将 mobx 与 React Hooks 一起使用? 关于

import classnames from 'classnames';
import { observer } from 'mobx-react';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import ViewStore from '../../../store/ViewStore';

interface INavbarProps {
  viewStore: ViewStore;
}

const Navbar = observer((props: INavbarProps) => {
  const { authed } = props.viewStore;

  const [drawerIsOpen, setState] = useState(false);

  function toggleMenu() {
    drawerIsOpen ? setState(false) : setState(true);
  }

  return (
    <div>
      <Link to="/">Home</Link>
      <Link to="/admin">Admin</Link>
      <Link to="/all">All</Link>
      {authed …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs mobx react-hooks

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

React Native Android:任务 :app:validateSigningRelease FAILED

我已经使用 Microsoft App Center 设置了 ci/cd。它与调试 APK 完美配合,但在构建发布 APK 时出现错误。证书已上传,应用程序中的所有内容均已正确设置。没有这样的问题,当我尝试构建它时,使用 npm 命令:
"android-release": "cd android && ./gradlew assembleRelease"

可能是什么问题?

> Task :app:validateSigningRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:validateSigningRelease'.
> 
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
Keystore file '/Users/vsts/agent/2.150.0/work/1/s/android/app/my-release-key.keystore' not found for signing config 'release'.

* Try:
Run with --stacktrace option to …
Run Code Online (Sandbox Code Playgroud)

android gradle react-native

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

Moment.js 以 ISO 格式向当前日期添加 7 天

我有来自服务器的 ISO 格式的日期:2019-02-28。如何使用 Moment.js 添加 7 天?

结果应该是2019-03-04。

javascript momentjs

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