草庐IT

no-mutating-props

全部标签

javascript - 如何在 ReactJS 中指定 null prop 类型?

我在ReactJS组件上有一个prop,它要么是null要么是一个ImmutableMap。如果我写在我的小部件的底部:MyComponent.propTypes={myMap:React.PropTypes.instanceOf(Immutable.Map)};我将其保留为null、undefined或Map的可能性。我怎样才能使它成为必需的并且类型为null或仅映射?https://facebook.github.io/react/docs/typechecking-with-proptypes.html我看到了这个例子,但我不知道如何根据我的需要调整语法,或者是否可能。编辑:如果

javascript - typescript : How to resolve 'rxjs/Rx has no exported member ' SubscriptionLike'

我在这里尝试遵循这个例子https://www.youtube.com/watch?v=gxCu5TEmxXE,但是在执行tsc-p时,出现错误。有什么我需要导入的吗?错误:node_modules/@angular/common/src/location/location.d.ts(1,10):错误TS2305:模块'"...functions/node_modules/rxjs/Rx"'没有导出成员'SubscriptionLike'。TS文件import"zone.js/dist/zone-node";import*asfunctionsfrom"firebase-functio

javascript - super(props) 为我的 React 组件做了什么?

我不太擅长JS和React。React文档位于here陈述以下内容:WhenimplementingtheconstructorforaReact.Componentsubclass,youshouldcallsuper(props)beforeanyotherstatement.Otherwise,this.propswillbeundefinedintheconstructor,whichcanleadtobugs.我的问题是这实际上是如何工作的?super()在我的构造函数中神奇地启用了this.props是做什么的? 最佳答案

javascript - 如何评估数据属性中的 Vue.js 组件 Prop ?

我有2个组件:Post和Comments。在Post组件中,有Comments组件,它有3个属性:postId、numCom(评论数)和comments(数组).我收到评论并通过props传递数组,现在我想在Comments组件中检索数组并将其添加到数据中,这样我就可以添加/删除评论等。这是我在Comments.vue中的代码:props:['id','numCom','comments'],data:function(){return{newMessage:"",loading:false,allComments:this.comments,num:this.numCom,}},但这

javascript - 了解 vue.js 中的 Prop

我正在阅读学习vue.js的指南,进入Prop部分,遇到了一个问题。我知道子组件有独立的作用域,我们使用props配置将数据从父组件传递到它,但是当我尝试它时我无法让它工作。我有theexampleI'mworkingonuponjsfiddle:varvm=newVue({el:'#app',//datafrommyparentthatIwanttopasstothechildcomponentdata:{greeting:'hi'},components:{'person-container':{//passinginthe'greeting'propertyfromthepare

javascript - 将自定义 Prop 传递给 react-router v4 中的路由器组件

我正在使用ReactRouter创建一个多页面应用程序。我的主要成分是并将所有路由呈现给子组件。我正在尝试通过路线传递Prop,并基于一些research我做到了,子组件利用传递下来的Prop的最常见方式是通过this.props.route他们继承的对象。但是,这个对象对我来说是未定义的。在我的render()在子组件中的功能,我console.log(this.props)并返回一个看起来像这样的对象{match:Object,location:Object,history:Object,staticContext:undefined}看起来完全不像我预期的Prop。这是我的详细代

javascript - 如何将 ESLint no-unused-vars 用于代码块?

我需要在ESLint中禁用一些变量检查。目前,我正在使用这段代码,但没有得到想要的结果:/*eslintno-unused-vars:["error",{"caughtErrorsIgnorePattern":"Hey"}]*/exporttypeHey={a:string,b:object}两个问题:是否有可以为代码块启用no-unused-vars的变体?有点像.../*eslintruledisable"*///Iwanttoplacemyblockofcode,here/*eslintruledisable"*/或者我可以让Hey成为一个全局变量,以便它在任何地方都可以被忽略吗

javascript - 在 ReactJS 中将包装器组件作为 props 传递

我正在尝试将包装器组件作为Prop传递。在React中这样的技术在技术上可行吗?importReact,{Component,PropTypes}from'react';importChildCompfrom'./child-comp';classCompextendsComponent{render(){const{Wrapper}=this.props;return();}}Comp.propTypes={};exportdefaultComp; 最佳答案 是的,这是完全可能的,而且很常用。唯一的问题是,作为约定,在JSX中大写

javascript - 仅 Chrome 错误 : XMLHttpRequest cannot load file URL No 'Access-Control-Allow-Origin' header is present on the requested resource

我正在按照书本示例进行操作,因此代码非常简单。这是代码:jQuery.get("ajax_search_results.php",{s:search_query},write_results_to_page,"html");代码是ajax_search_results.php有:FirstresultSecondresultThirdresultMore...这在Firefox中按预期工作。但是在Chrome中,我可以在JS控制台中看到以下错误消息:XMLHttpRequestcannotloadfile:///C:/xampp/xampp/htdocs/snk/ajax_search

javascript - 如何使用 React Apollo 2.1 的 Mutation 组件在 mount 上运行突变?

我们目前正在从Relay移动至ReactApollo2.1我正在做的事情似乎有问题。上下文:某些组件必须仅在用户通过身份验证(通过APIkey)时呈现,因此有一个Authenticator组件保护树的其余部分。在App.js中,它是这样使用的(显然下面的所有片段都是最小示例):importReactfrom'react';importAuthenticatorfrom'./Authenticator';importMyComponentfrom'./MyComponent';exportdefaultfunctionApp({apiKey}){return({if(error)retu