小编Sha*_*ika的帖子

从0.13升级到2.8.1后,React-router不起作用

我将react-router从版本0.13升级到2.8.1然后它给出了一个错误,说"无法加载资源:服务器响应状态为404(未找到)".

这是我的代码.

import React from 'react'
import Router from 'react-router'

import App from './components/app';
import Main from './components/main';
import CreateOrganization from './components/create-organization';
import ManageUsers from './components/manage-users';
import FldList from './components/fld-list';
import FldView from './components/fld-view';
import WeighIn from './components/weigh-in';
import MatchFlds from './components/match-flds';
import NotFound from './components/not-found';

var { Route, DefaultRoute, NotFoundRoute } = Router;

var routes = (
    <Route handler={App}>
        <DefaultRoute handler={Main} />
        <Route name="CreateOrganization" path="create-organization" handler={CreateOrganization}></Route>
        <Route name="manageUsers" path="manage-users" handler={ManageUsers}></Route>
        <Route name="fldList" path="fld-list" handler={FldList}></Route>
        <Route name="fldView" path="fld-view/:fldId" handler={FldView}></Route>
        <Route …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router

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

在 React Native 中使用多行自动增长文本输入

我创建了一个自定义组件,它在视图中包含一个 TextInput 和 Icon。当 TextInput 有多行时,我想增加我的视图高度。这是我的组件。我怎样才能做到这一点?

import React from "react";
import { View, TextInput, StyleSheet } from "react-native";
import { InputIcon } from "../";

const commentInput = props => (
  <View style={styles.inputContainer}>
    <TextInput
      {...props}
      underlineColorAndroid="transparent"
      style={[
        styles.input,
        { fontSize: props.fontSize },
        props.style,
        !props.valid && props.touched ? props.invalidInput : null
      ]}
    />
    <InputIcon
      name="upload"
      size={30}
      color="gray"
      onPress={props.onPress}
      disabled={props.disabled}
    />
  </View>
);

const styles = StyleSheet.create({
  inputContainer: {
    flexDirection: "row",
    alignSelf: "center",
    width: "96%",
    marginLeft: 2,
    marginRight: 2,
    marginBottom: 10,
    height: 50, …
Run Code Online (Sandbox Code Playgroud)

react-native

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

反应本机滚动到底部

当我单击 react native 中的输入时,我想将列表向下滚动到底部。

这是我的代码。

render() {
    return (
      <View style={styles.container}>
        <View style={styles.commentListWrapper}>
          <ScrollView>
            <Animated.View>
              <PostProfileBar
                profile={this.state.post.author}
                timeAgo={this.state.post.timeAgo}
              />

              <ClickableImage
                source={{ uri: this.state.post.postImage }}
                height={height * (3 / 10)}
                width={width}
                onPress={() => alert("Image Clicked")}
              />
            </Animated.View>

            <CommentFlatList
              data={this.state.data}
              refreshing={this.state.refreshing}
            />
          </ScrollView>
        </View>

        <View
          style={[
            styles.commentInputWrapper,
            { flex: this.state.commentBoxFlex }
          ]}
        >
          <CommentInput
            iconName="upload"
            placeholder="Type Comment"
            isFocused={true}
            fontSize={this.state.comment.value.length > 0 ? 16 : 20}
            value={this.state.comment.value}
            multiline={true}
            onChangeText={value => this.onChangeComment(value)}
            onPress={() => this.uploadComment()}
            invalidInput={styles.invalidInput}
            valid={this.state.comment.valid}
            touched={this.state.comment.touched}
            disabled={!this.state.comment.valid}
          />
        </View>
      </View>
    );
  } …
Run Code Online (Sandbox Code Playgroud)

react-native

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

只读反应原生TextInput

我想在我的RN应用程序中只读文本输入.我试图设置可编辑的道具,但它没有正常工作.我怎样才能做到这一点?

<DetailInput
  inputStyle={styles.inputStyles} 
  height={120}
  width={width - 40}
  multiline={true}
  numberOfLines={6}
  underlineColorAndroid="transparent"
  maxLength={500}
  editable={!userRegistrationInProgress}
  onChangeText={value => this.statementChangedHandler(value)}
/>

const detailInput = props => {

    return (
      <TextInput
        {...props}
        style=
          {[
            props.inputStyle,
            { height: props.height, width: props.width},
            !props.valid && props.touched ? props.invalidInput : null
          ]}
      />
    );
}

export default detailInput;
Run Code Online (Sandbox Code Playgroud)

react-native

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

反应功能组件解构

我学习了关于 udemy 的反应课程。我无法理解以下代码。const InputGroup = (, 之后的这个对象是什么?我看过教程使用道具,但这里没有使用道具。而是使用了一个对象。

const InputGroup = ({
  name,
  placeholder,
  value,
  error,
  icon,
  type,
  onChange,
  autoComplete,
}) => {
  return (
    <div className="input-group mb-3">
      <div className="input-group-prepend">
        <span className="input-group-text">
          <i className={icon} />
        </span>
      </div>
      <input
        type={type}
        className={classnames('form-control form-control-lg', {
          'is-invalid': error,
        })}
        placeholder={placeholder}
        name={name}
        value={value}
        onChange={onChange}
        autoComplete={autoComplete}
      />
      {error && <div className="invalid-feedback">{error}</div>}
    </div>
  )
}
Run Code Online (Sandbox Code Playgroud)

reactjs

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

在 javascript 中创建一个 util 类

我想为我的 React 应用程序创建一个 util 类。util 类应该是静态类,据我所知无法实例化。那么,在 javascript 中创建 util 类的正确方法是什么,我们如何使其成为静态的?

javascript

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

在反应本机中不推荐使用StackNavigator和TabNavigaor

在我的项目中,更新节点模块后,反应导航显示出一些问题.在控制台中,它说, tabBarBottom已被弃用.使用react-navigation-tabs包.不推荐使用stackNavigator函数名.不建议使用createStackNavigator tabNavigator.使用createBottomTabNavigator

import React from "react";
import { StackNavigator } from "react-navigation";
import { TabNavFooter } from "./TabNavFooter";
import { SIGNIN_KEY, SIGNUP_KEY } from "../config/routeKeys";
import {
  SignupScreen,
  SigninScreen,
  MainFeedScreen,
  CommentScreen,
  SharePostScreen
} from "../screens";

export const Routes = StackNavigator({
  mainfeed: { screen: TabNavFooter },
  signin: { screen: SigninScreen },
  signup: { screen: SignupScreen },
  comments: { screen: CommentScreen },
  sharePost: { screen: SharePostScreen }
});


import React from "react";
import { TabNavigator, TabBarBottom } from "react-navigation";
import { …
Run Code Online (Sandbox Code Playgroud)

react-native

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

我应该将验证放在节点模型内部吗?

在我的应用程序中,我的用户模型如下。当我验证确认密码时,猫鼬模型中存在一些业务逻辑部分。我怎样才能以更好的方式表达这个?我应该将验证部分与模型分开吗?或者我应该将验证保留在猫鼬模型中?

import Joi from 'joi';
import { Schema, model } from 'mongoose';

const userSchema = new Schema(
  {
    firstName: {
      type: String,
      required: true,
      minlength: 2,
      maxlength: 30,
    },
    lastName: {
      type: String,
      required: true,
      minlength: 2,
      maxlength: 30,
    },
    email: {
      type: String,
      required: true,
      minlength: 5,
      maxlength: 100,
      unique: true,
      lowercase: true
    },
    password: {
      type: String,
      required: true,
      minlength: 8,
      maxlength: 1024,
    },
    avatar: {
      type: String
    },
  }, 
);

export const User = model('User', userSchema);

/** …
Run Code Online (Sandbox Code Playgroud)

node.js

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

反应本机时刻格式化日期无效

我的 RN 应用程序中有以下代码。

  getFormattedDate = (date) => {
    const formattedDate = moment(new Date(date)).format('MMMM, DD YYYY');
    return { date: formattedDate };
  }
Run Code Online (Sandbox Code Playgroud)

当我在模拟器上运行它时,格式化的日期会正确显示。但是当我在设备上运行它时,它说日期无效。我在这里做错了什么?

javascript node.js momentjs react-native

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

立即格式化特定日期

在我的本机应用程序中,我有一个日期字段,它具有这样的值。2005-7-16

现在,我想使用矩将其转换为“ DD / MM / YYYY”格式。但这给出了一个错误。

return moment('2005-7-16').format('MM/DD/YYYY');
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

momentjs

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