小编dan*_*nte的帖子

react-hook-form,总是返回字符串类型值

我正在使用react-hook-form。我正在尝试使用这个库实现购物车,但在获取数值方面遇到了困难。使用 getValues("count")时,即使设置type="number", name="count"始终返回字符串值的输入标记。

对于name="count"的字符串值,我的自定义函数增量无法按预期工作。当我单击 + 按钮时,它返回并添加了字符串。

import React, { FC, useEffect } from 'react';
import * as Styled from './style';
import { useForm, ErrorMessage} from 'react-hook-form';
import { ItemCountForm  } from 'src/models/item-count'; 
export const CountForm:FC<{
  partialData : Omit<ItemCountForm,'count'>
}> = ({
  partialData
}) => {

  const { register, handleSubmit, errors,getValues, setValue } = useForm<{count:number}>({
    defaultValues:{
      count: 1}
  });

  const onSubmit = async(data: {count: number}) => { 
    console.log('submitted');
    const formData: ItemCountForm = { …
Run Code Online (Sandbox Code Playgroud)

reactjs react-hook-form

14
推荐指数
2
解决办法
2万
查看次数

No overload matches this call in saga call effect

I want to pass action.url string as a parameter of topicDummy function which return Promise, but It keeps show me

No overload matches this call.
  The last overload gave the following error.
    Argument of type '<TopicData>(url: string) => Promise<TopicData>' is not assignable to parameter of type '{ context: unknown; fn: (this: unknown, ...args: any[]) => any; }'.
      Type '<TopicData>(url: string) => Promise<TopicData>' is missing the following properties from type '{ context: unknown; fn: (this: unknown, ...args: any[]) => any; }': …
Run Code Online (Sandbox Code Playgroud)

saga typescript reactjs redux

7
推荐指数
2
解决办法
1万
查看次数

redux 减速器类型 'never'

我想使用“useSelector”来选择 rootStore 的正确状态,但无法正确获取状态。原因是RootState的主题缩减器从未给我类型

export type RootState = ReturnType<typeof rootReducer>
Run Code Online (Sandbox Code Playgroud)

如何正确获取主题类型?

整个代码看起来像

///topic.ts 
import { Action, ActionCreator } from 'redux';
import { CardData } from '@models/card';
import { TopicName } from 'src/models/topic';
import { ActionEnum } from './index';

//action
export enum TopicEnum {
  FETCH_TOPIC = "FETCH_TOPIC"
}
type TopicType = ActionEnum | TopicEnum;  

export interface TopicBasicState{
  topic: TopicName
  isLoading :boolean
  data: CardData[]
  isError: boolean 
}
export const initialState: TopicBasicState = {
  topic: 'all',
  isLoading: true,
  data: [] …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs redux

5
推荐指数
1
解决办法
5086
查看次数

我什么时候应该将 'className' 属性传递给反应组件?

一些 React 组件将className属性传递给子组件。我没有看到任何需要className在我的项目中作为支柱传递。

className为什么使用这个道具?我什么时候应该采用这种方法?

import styled from 'styled-components' 

const ReactComponent = ({ className }) => {
  return <div className={className}/>
}

const StyledComponent = styled(ReactComponent)``;
Run Code Online (Sandbox Code Playgroud)

reactjs styled-components

4
推荐指数
1
解决办法
7265
查看次数

打字稿中的 Pick&lt;T, "properties"&gt; 和 T["properties"] 有什么不同

我是打字稿初学者。

Pick和 T["properties"] 索引引用有什么区别?

例如:

interface Generic {
   red: number
   apple: string;
   
}

type RedType = Pick<Generic, "red">
type RedType2 = Generic["red"]
Run Code Online (Sandbox Code Playgroud)

typescript

3
推荐指数
1
解决办法
146
查看次数

我怎么能不选择样式组件的最后一个元素

这是我的代码结构


const StyledArticle = styled.article``;

const StyledDiv = styled.div``; 

 <StyledArticle>
   <StyledDiv>1</StyledDiv>
   <StyledDiv>2</StyledDiv>  
   <StyledDiv>3</StyledDiv> 
   <StyledDiv>4</StyledDiv>  
 </StyledArticle> 
Run Code Online (Sandbox Code Playgroud)

除了第 4 个 StyledDiv,我如何添加 css StyledDiv 1,2,3。

无需在 StyledArticle 中添加任何 css 语句

没有 js,jquery 只使用 css。

css styled-components

2
推荐指数
1
解决办法
1386
查看次数