草庐IT

windowFlags-prop

全部标签

javascript - 将 Prop 传递给 React Router 子路由

我无法克服react路由器的问题。场景是我需要从状态父组件和路由向子路由传递一组Prop。我想做的是将childRouteA传递给propsA,并将childRouteB传递给propsB。但是,我能弄清楚如何做到这一点的唯一方法是同时传递RouteHandlerpropsA和propsB这意味着每个子路径都会得到每个子路径Prop不管它是否相关。目前这不是一个阻塞问题,但我可以看到有一段时间我会使用同一组件的两个,这意味着propA上的键将被propB上的键覆盖。#routesroutes=()#Parentcomponentrender:->timeProps:->foo:'bar

javascript - React Prop - 如果另一个 Prop 为空/空,则在 Prop 上设置 isRequired

我有一个组件.如果组件没有this.props.children,我想设置PropariaLabel作为isRequired,否则in可以是可选的。我该怎么做?ariaLabel不需要Prop:AddtobagariaLabelProp必须是必需的:如果this.props.children和this.props.ariaLabel是空的,它会抛出一个错误说this.props.ariaLabel是isRequired属性类型:Button.propTypes={/**iconinsideButton.*/icon:React.PropTypes.object,/**Contentin

javascript - react : adding props to an existing component

我正在尝试弄清楚如何使用附加Prop克隆现有元素。供引用:this.mainContent=我试图做类似的事情React.createElement(this.mainContent,Object.assign({},this.mainContent.props,{anotherMessage:"nicetomeetya!"}));但它不起作用。我将如何完成这个? 最佳答案 您需要克隆元素并使用React.cloneElement添加额外的Prop例如:constClonedElementWithMoreProps=React.cl

javascript - React react-router-dom 将 Prop 传递给组件

我需要使用路由器将Prop传递给组件。这是我的代码:importReact,{Component,PropTypes}from'react';import{connect}from'react-redux';importAppBarTopfrom'./appbar/AppBarTop';importLoginfrom'../pages/login/Login';import{BrowserRouterasRouter,Route}from'react-router-dom';classAppextendsComponent{render(){const{isAuthenticated}

javascript - React 内联样式 - style prop 需要从样式属性到值的映射,而不是字符串

我正在尝试在我的React应用程序中设置内联样式。在这种情况下,对于跨度:React告诉我:UncaughtInvariantViolation:Thestylepropexpectsamappingfromstylepropertiestovalues,notastring.Forexample,style={{marginRight:spacing+'em'}}whenusingJSX.ThisDOMnodewasrenderedby`SentenceView我不太清楚这是什么意思。PS:我尝试了不同的版本,所以我做了paddingRight:5以及paddingRight:5+'

javascript - react native : No propType for native prop RCTView. 最大高度

升级到RN0.30后,即使构建最简单的可能,我也开始看到下面显示的错误app:react-nativeinitAwesomeProjectreact-nativerun-ios最奇怪的是组件BlurView、VibrancyView和RNSearchBar包含在警告消息中,尽管项目没有使用它们。重新编译/清理项目并不能解决问题。控制台和错误:2016-07-2208:48:02.985[warn][tid:main][RCTEventEmitter.m:52]Sending`websocketFailed`withnolistenersregistered.2016-07-2208:4

javascript - 失败的形式 propType : You provided a `value` prop to a form field without an `onChange` handler

当我加载我的React应用程序时,我在控制台中收到此错误。Warning:FailedformpropType:YouprovidedavalueproptoaformfieldwithoutanonChangehandler.Thiswillrenderaread-onlyfield.IfthefieldshouldbemutableusedefaultValue.Otherwise,seteitheronChangeorreadOnly.ChecktherendermethodofAppFrame.我的AppFrame组件如下:classAppFrameextendsCompone

javascript - 警告 : Failed propType: Invalid prop `component` supplied to `Route`

我正在尝试新的react-router1.0.0,我收到了我无法解释的奇怪警告:Warning:FailedpropType:Invalidprop`component`suppliedto`Route`.Warning:Invalidundefined`component`suppliedto`Route`.应用很简单:importReactfrom'react';importReactDOMfrom'react-dom';import{Router,Route}from'react-router';importAppfrom'./components/app';varSpeaker

javascript - react : inline conditionally pass prop to component

我想知道是否有比使用if语句更好的有条件地传递prop的方法。例如,现在我有:varparent=React.createClass({propTypes:{editable:React.PropTypes.bool.isRequired,editableOpts:React.PropTypes.shape({...})},render:function(){if(this.props.editable){return();}else{//Inthiscase,ChildwillusetheeditableOptsfromitsowngetDefaultProps()return();

javascript - react-router 在子组件中获取 this.props.location

据我了解将给出App与路由相关的Prop,如location和params.如果我的App组件有许多嵌套的子组件,我如何让子组件访问这些Prop而不需要:从App传递props使用窗口对象为嵌套的子组件创建路由我以为this.context.router会有一些与路线相关的信息,但是this.context.router似乎只有一些操作路线的功能。 最佳答案 V6您可以使用useNavigate,useLocation和useMatch在您的组件中获取matchPath,navigate和location.constChild=()