草庐IT

react-promise

全部标签

javascript - React + Webpack HMR 正在刷新页面(不是热加载)

我在让react-hotwebpack加载器正常工作时遇到了一些麻烦。当我加载页面时,我会得到以下信息:[HMR]WaitingforupdatesignalfromWDS...[WDS]HotModuleReplacementenabled.但是当我保存更改时,页面会自动硬刷新浏览器(而不是HMR替换)。//webpack.config.js{entry:{client:'webpack-dev-server/client?http://localhost:8786',//WebpackDevServerhostandportapp:"./HelloWorld.tsx"},devto

javascript - 如何使用 promise ,或在函数完成之前完成 ajax 请求?

我有以下功能来检查用户session以查看他们是否是员工。现在,我知道有更好的方法可以做到这一点,但我正在尝试制作一个与论坛软件绑定(bind)的简单应用程序。functionisStaff(callback){$.ajax({url:url}).done(function(data){varsession=$.parseJSON(data);if(session.is_staff===1){callback(true);}else{callback(false);}});}假设我在编译“帖子”(Handlebars)时像这样使用这个函数。functioncompilePost(pos

javascript - Promise.all 找到哪个 promise 被拒绝

在我的代码中,我使用Promise.all()在某些promise全部实现后异步运行代码。有时,一个promise会失败,我不确定为什么。我想知道哪个promise失败了。将回调作为第二个参数传递给.then方法没有多大帮助,据我所知that一个promise正在拒绝,但不是哪个promise正在拒绝。堆栈跟踪也无济于事,因为第一项是Promise.all()的错误处理程序。传递给Promise.all()的try函数的第二个函数的第一个参数的Error对象的行号是只是我记录行号的行的行号。有没有人知道有什么方法可以查明哪个promise被拒绝了? 最佳答案

javascript - react .createElement : type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object

预计我应该能够导出我的App组件文件并将其导入到我的index.js中。结果出现以下错误React.createElement:typeisinvalid--expectedastring(forbuilt-incomponents)oraclass/function(forcompositecomponents)butgot:object我的index.jsconstReact=require('react');constReactDOM=require('react-dom');constApp=require('./components/App');require('./inde

javascript - 根据名称渲染 React 组件

上下文:我正在开发一个基于小部件的Web应用程序(就像已停用的iGoogle,用户可以在其中选择他们想要显示的小部件)。每个小部件都是一个React组件。简化示例:这里有2个不同的小部件varHelloWidget=React.createClass({render:function(){returnHello{this.props.name};}});varHiWidget=React.createClass({render:function(){returnHi{this.props.name};}});作为用户,我选择了HiWidget,我的名字是“dude”,所以当系统从持久层

javascript - 你如何在 react-select v2 中创建 optgroup?

我想在我的react-select列表中包含optgroups,但它似乎没有在任何地方记录。我有以下结构,这是我从https://github.com/JedWatson/react-select/issues/59中的评论中提取的:render(){constoptions=[{label:"Group1",children:[{label:"Group1,option1",value:"value_1"},{label:"Group1,option2",value:"value_2"}]},{label:"Arootoption",value:"value_3"},{label:"

javascript - IndexedDB 事务和 Promises 之间的相互作用不一致

我看到sync-promise发布在Reddit和gotintoadiscussionwiththeauthor上。我们注意到IndexedDB事务和promise之间的关系存在一些奇怪的不一致。IndexedDB事务在所有onsuccess事件完成时自动提交。一个复杂的问题是,您不能在onsuccess回调中执行任何异步操作,除非对同一事务执行另一个操作。例如,您不能在onsuccess中启动AJAX请求,然后在AJAX请求返回一些数据后重用同一事务。promise与它有什么关系?据我了解,promise解决应该始终是异步的。这意味着您不能在不自动提交IndexedDB事务的情况下使

javascript - React.js 和 ES6 : Any reason not to bind a function in the constructor

我正在将React组件更新为ES6,遇到了这个问题中描述的问题-UnabletoaccessReactinstance(this)insideeventhandler-即不绑定(bind)到组件实例。这是有道理的,当然也行得通,但我对答案的另一部分感到困惑:Beawarethatbindingafunctioncreatesanewfunction.Youcaneitherbinditdirectlyinrender,whichmeansanewfunctionwillbecreatedeverytimethecomponentrenders,orbinditinyourconstru

javascript - this.state 在 react native 的 onPress 事件期间未定义

你好,我是ReactNative的新手,我的代码是:importReact,{View,Text,TextInput,Component}from'react-native';importStylefrom'./styles/signin';importButtonfrom'../common/button';exportdefaultclassSignInextendsComponent{constructor(props){super(props);this.state={email:'',password:''};}render(){return(Emailthis.setSta

javascript - React.js - 创建简单的表格

很抱歉这似乎是一个新手问题(工作到很晚才开始使用React),但我正在尝试弄清楚如何使用nxn维度。例如,在我的组件中,渲染输出将是这样的:每一行都有自己的id,每个单元格也是如此。初始状态constructor(props){super(props);this.state={size:3}}是什么设置表的大小。让我思考的是如何在JSX中实现for循环。 最佳答案 睡了一觉后,我想通了:importReact,{Component}from'react'exportdefaultclassExampleextendsComponen