草庐IT

mobx-state-tree

全部标签

javascript - 如何获得类型化 react 组件属性的代码完成?

我正在使用react和mobx-state-tree,我使用@inject将商店注入(inject)我的组件。所以最后我通过组件内部的this.props.uiStore访问商店。不幸的是,VisualStudioCode无法推断我的商店类型,因此我没有任何属性的代码完成。我想知道我是否可以为此使用jsDoc(因为它非常适用于方法),但找不到方法。我在想一些类似的事情:exportdefaultclassDeviceMirrorextendsReact.Component{/***@namespace*@property{object}props*@property{UiStore}p

javascript - 什么是 Tree Shaking,我为什么需要它?

我已经开始学习Angular2并遇到了“treeshaking”这个术语,但我无法从初学者的Angular找到任何好的解释。我这里有两个问题:什么是treeshaking,我为什么需要它?如何使用它? 最佳答案 我看到你在这里有三个问题;1。什么是摇树?2.有什么需要?3.以及,你如何使用它?1。什么是treeshaking?treeshaking指的是死代码消除。这意味着在构建过程中未使用的模块将不会包含在包中。WhenweimportandexportmodulesinJavaScript,mostofthetimetherei

javascript - React - 改变 this.state onClick 用 array.map() 呈现

我是React和JavaScript的新手。我有一个Menu组件,它呈现一个动画onClick,然后将应用程序重定向到另一个路径,/coffee。我想将单击(选择)的值传递给函数this.gotoCoffee并更新this.state.select,但我不知道如何,因为我在同一onClick事件中映射this.state.coffees中的所有项目。我如何做到这一点并将this.state.select更新为点击值?我的代码:classMenusextendsComponent{constructor(props){super(props);this.state={coffees:[]

javascript - react 中的 "Cannot update during an existing state transition"错误

我正在尝试执行本ReactJS教程的第15步:React.jsIntroductionForPeopleWhoKnowJustEnoughjQueryToGetBy作者推荐如下:overflowAlert:function(){if(this.remainingCharacters()Oops!TooLong:);}else{return"";}},render(){...{this.overflowAlert()}...}我尝试执行以下操作(我觉得没问题)://initialized"warnText"inside"getInitialState"overflowAlert:func

javascript - react + 助焊剂 : Getting initial state into a store

我们最近从Angular切换到React+Flux来构建一个相当复杂的业务应用程序。采用让一个容器组件将所有状态作为属性传递到组件树下的方法并不是为我们开发应用程序的实用方法,因为该应用程序使用类似页面的大型模式。确实有足够的状态传递给模式,以便他们将数据加载到他们的存储中。我遇到的问题是我需要将一些初始状态(作为Prop传递)放入模态组件的商店中。在thispostFacebook的好人说,当同步不是目标时,可以使用props作为初始状态。这就是我目前将初始状态放入我的商店的方式:varABC=React.createClass({...getInitialState:functio

javascript - react : Can I check if a state exists before rendering it

我是React的新手,我制作了一个显示用户名user的导航栏{this.state.name}但问题是如果用户未登录,我会收到一个错误,因为this.state.name未定义。有什么方法可以在将它呈现为导航栏的一部分之前检查是否已定义this.state.name还是有更好的方法来消除此错误? 最佳答案 当然,使用三元:render(){return(this.state.name?{this.state.name}:null);}甚至更短render(){return(this.state.name&&{this.state.n

javascript - 使用带有异步函数和 .then 的 MobX @action 装饰器

我正在使用MobX2.2.2尝试在异步操作中改变状态。我将MobX的useStrict设置为true。@actionsomeAsyncFunction(args){fetch(`http://localhost:8080/some_url`,{method:'POST',body:{args}}).then(res=>res.json()).then(json=>this.someStateProperty=json).catch(error=>{thrownewError(error)});}我得到:Error:Error:[mobx]Invariantfailed:Itisnota

javascript - Angular ui 路由器 : how do I reload a state when a path parameter changes but not reload when a query parameter changes?

例如,我希望导航中的此更改能够重新加载状态:#/detail/1#/detail/2但是我不希望这个导航重新加载状态:#/detail/1?search=blah#/detail/1?search=huzzah根据ui-router文档,设置reloadOnSearch:false应该可以完成此操作,但请尝试下面的方法。当reloadOnSearch===false时,更改路径参数不会重新加载状态,即使文档说它应该。Plunkr:http://run.plnkr.co/ZPy9uabYlkMilwdS/#/param 最佳答案 我创

javascript - 为什么会出现这个错误 : "Invariant Violation: Cannot update during an existing state transition"

我似乎在一个大型应用程序中遇到了这个错误(但我不确定在哪里):UncaughtError:InvariantViolation:setState(...):Cannotupdateduringanexistingstatetransition(suchaswithinrender).Rendermethodsshouldbeapurefunctionofpropsandstate.我怀疑这可能是在setTimeout或setInterval中使用setState的结果。这引出了我真正的问题:为什么会存在这个错误?是否有一些概念上的原因我错过了为什么ReactJS不只是排队状态和Prop

javascript - AngularUI 路由器 : multiple states with same url pattern

嘿,我遇到了一个我认为是常见的路由问题,但我无法找出解决方案。基本上我的页面有两种状态,基本状态和高级状态,我希望两种状态的URL模式相同,但当时只加载当前状态的模板(从Controller内部转换到)config(function($stateProvider){$stateProvider.state('basic',{url:'/:post',templateUrl:function(stateParams){return'post-'+stateParams.post+'-tmpl.html';}});$stateProvider.state('advanced',{url:'