使用Redux-Form中的initializingFromState示例,我试图动态设置它.这是为了编辑书籍列表中的特定书籍,并使用在express.js中设置的简单api.
整个容器在下面.我不知何故需要initialValues在mapStateToProps函数内传入.在这个例子中,它是通过一个静态对象完成的,但我无法弄清楚如何使用我通过via引入的信息fetchBook,并将其传递给initialValues.
容器:
import React, { Component, PropTypes } from 'react';
import { reduxForm } from 'redux-form';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { fetchBook, editBook } from '../actions/index';
class BookEdit extends Component {
componentWillMount() {
this.props.fetchBook(this.props.params.id);
}
static contextTypes = {
router: PropTypes.object
}
onSubmit(props) {
this.props.editBook(this.props.book.id, props)
.then(() => {
this.context.router.push('/');
});
}
const data = {
title: {this.props.book.title},
description: {this.props.author} …Run Code Online (Sandbox Code Playgroud) react-load-script我正在努力为Create React App 应用程序添加类型声明。
在该src文件夹中,我创建了一个react-load-script.d.ts文件并添加了以下内容:
// Type definitions for React Load Script
declare module 'react-load-script' {
import * as React from 'react'
interface Script {
url: string
}
}
Run Code Online (Sandbox Code Playgroud)
通过以上我得到的错误:
JSX 元素类型“Script”没有任何构造或调用签名。
我哪里错了?这是模块: https: //github.com/blueberryapps/react-load-script
这是我目前在应用程序中使用它的情况:
<Script url="https://maps.googleapis.com/maps/api/js? key=your_api_key&libraries=places"
/>
Run Code Online (Sandbox Code Playgroud)
我还需要为 onLoad 添加类型:
<Script url="https://maps.googleapis.com/maps/api/js? key=your_api_key&libraries=places"
onLoad={this.handleScriptLoad}
/>
Run Code Online (Sandbox Code Playgroud)
非常感谢。
根据评论更新
我将声明文件移动并重命名为/@types/react-load-script/index.d.ts
在tsconfig.json我添加了以下内容compilerOptions:
"typeRoots": ["./node_modules/@types", "./@types"]
这是index.d.ts全部内容:
// Type definitions for React Load Script
import React from 'react'
export …Run Code Online (Sandbox Code Playgroud) 我收到一个奇怪的错误:vue-resource.common.js Uncaught TypeError: str.replace is not a function它似乎与我正在进行的获取一些数据的ajax调用有关:
export default {
data: () => ({
recipes: []
}),
ready() {
this.$http.get('http://localhost:3000/recipes', {
headers: {
'Access-Control-Allow-Origin': true
}
}).then((recipes) => {
this.$set('recipes', recipes)
})
}
};
Run Code Online (Sandbox Code Playgroud)
我是vue.js的新手并且真的不确定如何调试这个...任何指针都会很棒.
非常感谢.
我正在运行时,下面的错误yarn run test上create-react-native-app:
$ yarn run test
yarn run v1.0.1
$ node node_modules/jest/bin/jest.js --watch
2017-09-13 14:53 node[2839] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-09-13 14:53 node[2839] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-09-13 14:53 node[2839] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-09-13 14:53 node[2839] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
throw er; // Unhandled 'error' event
^
Error: Error watching file for changes: EMFILE
at exports._errnoException (util.js:1022:11) …Run Code Online (Sandbox Code Playgroud) 假设我有一个函数从其他对象组成一个对象,我将参数传递给函数 - 最初是一个对象文字,然后是我想要组合的对象来扩展对象:
composeFunc({}, obj1, obj2, obj3);
Run Code Online (Sandbox Code Playgroud)
传递的args数是可选的,我如何将args传递给Object.assign()第二个arg开始.所以该函数类似于以下内容:
function composeObj(objs) {
return Object.assign(arguments[1], arguments[2], arguments[3]... etc);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢 :)
如何从标准JS日期对象格式化日期,该日期对象来自服务器,并通过REST API通过Redux提供给React,其初始输出为:
"2016-05-16T13:07:00.000Z"
Run Code Online (Sandbox Code Playgroud)
成不同的格式?所以它被列为DD MM YYYY?
我可以通过操作请求结果或有效负载在Reducer of Action中执行此操作:
import { FETCH_BOOKS, FETCH_BOOK } from '../actions';
const INITIAL_STATE = { books: [], book: null };
export default function(state = INITIAL_STATE, action) {
switch(action.type) {
case FETCH_BOOK:
return { ...state, book: action.payload.data };
case FETCH_BOOKS:
return { ...state, books: action.payload.data };
}
return state;
}
Run Code Online (Sandbox Code Playgroud)
行动:
export function fetchBooks() {
const request = axios.get('/api/books');
return {
type: FETCH_BOOKS,
payload: request
}
}
Run Code Online (Sandbox Code Playgroud)
fetchBooks()componentWillMount()在Books React组件的方法中调用:
componentWillMount() {
this.props.fetchBooks(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试推送一个数组元素,但正在销毁那里的所有内容并替换为推送的数据:
db .collection('households')
.doc(householdId)
.set( { users: [uid], }, { merge: true }, )
.then(() => { resolve(); })
.catch(() => reject());
Run Code Online (Sandbox Code Playgroud)
我认为合并真不会破坏已经存在的数据?与 firestore api 文档有点挣扎。
这是我的数据结构:
households
2435djgnfk
users [
0: user1
1: user2
]
Run Code Online (Sandbox Code Playgroud)
谢谢!
我对Ramda和函数式编程非常陌生,并尝试使用Ramda重写脚本,但不确定如何以一种干净的方式处理Ramda的错误。这就是我所拥有的,没有人有任何关于如何使用Ramda以功能方式重写它的指针吗?
const targetColumnIndexes = targetColumns.map(h => {
if (header.indexOf(h) == -1) {
throw new Error(`Target Column Name not found in CSV header column: ${h}`)
}
return header.indexOf(h)
})
Run Code Online (Sandbox Code Playgroud)
为了参考,这些是的值header和targetColumns
const header = [ 'CurrencyCode', 'Name', 'CountryCode' ]
const targetColumns = [ 'CurrencyCode', 'Name' ]
Run Code Online (Sandbox Code Playgroud)
所以我需要:
-1我想在React应用程序中发出一个http请求,我想知道最好的方法是什么.我知道在Angular中你可以使用$http.get,所以类似于:
$http.get('API').success(function(data) {...
Run Code Online (Sandbox Code Playgroud)
但是我可以在React App中为同一目的使用什么.像Axios这样的东西会起作用吗?
请原谅我的无知,这里有新手.
我正在尝试使用 moment JS 格式化货币值的输出,并使用他们网站上的示例'$ 0,0[.]00'并针对英镑进行编辑'\xc2\xa3 0,0[.]00',仅输出值,而不输出英镑符号。
数字不支持美元以外的货币吗?
\n\n我正在使用的代码是:
\n\nnumeral(200).format('\xc2\xa3 0,0[.]00')\nRun Code Online (Sandbox Code Playgroud)\n 完全难倒,我有一个动作,根据用户是否登录设置状态 - isAuthenticated布尔和用户对象.
该操作肯定会触发,auth reducer正在运行,但是没有触发该情况,因此状态未更新:
行动:
export const SET_CURRENT_USER = 'SET_CURRENT_USER'
export function setCurrentUser (user) {
console.log(SET_CURRENT_USER)
return {
type: SET_CURRENT_USER,
user
}
}
Run Code Online (Sandbox Code Playgroud)
减速器
import isEmpty from 'lodash/isEmpty'
import SET_CURRENT_USER from '../actions/authActions'
const INITIAL_STATE = {
isAuthenticated: false,
user: {}
}
export default function (state = INITIAL_STATE, action) {
// console.log('action.type = ', action.type) <<< This is outputting the correct action type: SET_CURRENT_USER
switch (action.type) {
case SET_CURRENT_USER:
console.log('set cur user reducer') // this is not running
console.log(!isEmpty(action.user)) // …Run Code Online (Sandbox Code Playgroud) javascript ×10
reactjs ×5
redux ×3
ajax ×1
firebase ×1
node.js ×1
ramda.js ×1
redux-form ×1
typescript ×1
vue.js ×1
watchman ×1