草庐IT

函数组件

全部标签

javascript - screen.lockOrientation 不是函数

我想在Chrome中使用Js中的API屏幕。if(navigator.userAgent.match(/(android|iphone)/gi)){if('orientation'inscreen){//console.log('//APIsupported,yeah!');//console.log('neworientationis',screen.orientation);screen.lockOrientation('landscape');}else{console.log('//APInotsupported');}}else{//alert('none');}我的错误js

javascript - Immutable.Map.deleteAll() 不是函数

考虑以下代码:constperson=Immutable.Map({name:'John',surname:'Maverick',age:39});constmutated=person.deleteAll(['name','age']);预期结果是mutated现在是Map的新实例,其中键name和age已删除。但是,抛出异常:UncaughtTypeError:person.deleteAllisnotafunction检查Immutable.Map原型(prototype)的可用方法时,没有deleteAll和removeAll方法。它们被移除了吗?该方法在ImmutableJS

javascript - 将 Redux 状态传递给组件时的最佳实践

我正在与其他几个开发人员一起开发一个React+Redux项目,但我们无法就在何处传递状态和操作的最佳实践达成一致。我的方法是拥有一个“容器”或“提供者”组件,它是父组件,所有必需的状态和操作都映射到状态并向下传递到子组件,从而创建单一的真实来源。然而不利的一面是,您必须记住通过每个子组件向下传递操作和值,这可能很难遵循。另一种开发人员方法是在每个需要它的组件上,在堆栈中的任何位置使用mapStateToProps。因此,如果向下三层或四层的子组件需要特定状态,他将在该组件上使用mapStateToProps。他还会使用import关键字直接导入Action创建器,而不是将它们称为Pr

javascript - 在 React 组件中使用 setInterval

我正在阅读React官方网站上的教程。在生命周期方法的例子中,在componentDidMount方法下,给setInterval函数设置了一个timerID。我的问题是,即使timerID已初始化,但它从未在整个应用程序中被调用,应用程序如何在不在应用程序的任何地方显式调用timerID的情况下工作。这是下面的代码。classClockextendsReact.Component{constructor(props){super(props);this.state={date:newDate()};}componentDidMount(){this.timerID=setInterv

javascript - 通过 this 在 typescript 中从派生类型调用构造函数

在我的typescript中,我试图通过基类中的方法创建/克隆子对象。这是我的(简化的)设置。abstractclassBaseClass{protectedprops:TCompositionProps;protectedcloneProps():TCompositionProps{return$.extend(true,{},this.props);}//canbeoverwritenbychildsconstructor(props:TCompositionProps){this.props=props;}clone(){constprops=this.cloneProps();

javascript - 通过几个函数映射数组项

有没有比这个更优雅的方法来为数组中的每个项目连续执行几个函数:typeTransform=(o:T)=>T;typeItem={/*properties*/};transform(input,transformers:Transform[]){constitems:Item[]=getItems(input);returnitems.map(item=>{lettransformed=item;tramsformers.forEach(t=>transformed=t(transformed));returntransformed;})} 最佳答案

javascript - JavaScript 中的递归异步函数

我正在尝试在JavaScript中使用async/await编写递归函数。这是我的代码:asyncfunctionrecursion(value){returnnewPromise((fulfil,reject)=>{setTimeout(()=>{if(value==1){fulfil(1)}else{letrec_value=awaitrecursion(value-1)fulfil(value+rec_value)}},1000)})}console.log(awaitrecursion(3))但是我有语法错误:letrec_value=awaitrecursion(value-

javascript - React Redux - 在辅助函数中访问现有商店

我试图在React组件之外获取商店实例(商店状态),即在单独的辅助函数中。我有我的reducer,我的Action,我在最上面的组件中创建了一个商店。//configStore.jsimport{createStore}from'redux';importgeneralReducersfrom'../reducers/generalReducers';exportdefaultfunctionconfigStore(initialState){returncreateStore(generalReducers,initialState);}//index.jsimport{Provid

javascript - 实用程序.crypto.lib。 randomBytes 不是函数 : aws cognito js throws error on authentication

我收到以下错误:TypeError:__WEBPACK_IMPORTED_MODULE_0_aws_sdk_global__.util.crypto.lib.randomBytesisnotafunction当我尝试使用我编写的以下代码对用户进行身份验证时:import{CognitoUserPool,CognitoUserAttribute,CognitoUser,AuthenticationDetails}from'amazon-cognito-identity-js';letauthenticationDetails=newAuthenticationDetails({Usern

javascript - 组件上的异步等待已挂载

这是我的componentDidMount方法。我想设置当前用户的状态,然后在设置该用户时调用该函数。我该怎么做?componentDidMount=()=>{firebase.auth().onAuthStateChanged((user)=>{if(user){this.setState({user:user})}});this.props.retrieveMatches(this.state.user.uid)}我试过使用async/await但我在这里没有正确使用它:asynccomponentDidMount=()=>{awaitfirebase.auth().onAuthS