ค้นหาเว็บไซต์

reactjs - ฉันทดสอบ callback ของคอมโพเนนต์ React ที่ห่อด้วย withRouter อย่างไร?

ฉันกำลังใช้ Jest และ Enzyme เพื่อทดสอบโปรเจกต์ React ที่เขียนด้วย TypeScript ฉันมีคอมโพเนนต์หนึ่งที่ถูกห่อหุ้มใน React-Router router และมันหน้าตาประมาณนี้:

import { SomeButton } from './someButton'; import { RouteComponentProps, withRouter } from 'react-router'; const SomeButtonWithRouter = withRouter<{buttonCallback: () => void}>(SomeButton); export class SomePage extends React.Component <RouteComponentProps<{}>, {}> { constructor(props: {}) { super

อ่านต่อไป →

javascript - แปลง jsx เป็นคอมโพเนนต์ของ react?

สมมติว่าฉันมีคอมโพเนนต์ที่ชื่อ 'MyComponent' และฉันต้องการเก็บมันไว้ในตัวแปรประเภท 'MyComponent' ใน TypeScript แต่ใช้องค์ประกอบ JSX เพื่อเริ่มต้นมัน อะไรประมาณนี้:

let comp: MyComponent = <MyComponent somePropInit={3} />

โค้ดข้างต้นสร้างข้อผิดพลาดเช่น:

'property 'componentDidMount' หายไปในชนิด 'Ele

อ่านต่อไป →

reactjs - ต้องการความช่วยเหลือในการตั้งค่า react-hot-loader

ฉันกำลังใช้เทมเพลต ASP.NET 2.0 react SPA เวอร์ชันล่าสุด ซึ่งสร้างขึ้นด้วยคำสั่ง dotnet new react. มันใช้งานได้ดีทันทีโดยไม่ต้องปรับแต่ง ซึ่งรองรับการแทนที่โมดูลแบบร้อน (การแก้ไขโค้ดจะอัปเดตในเบราว์เซอร์โดยอัตโนมัติ)

จากนั้นฉันต้องการเพิ่มคอนเทนเนอร์แอประดับบนสุด ชื่อว่า App เพื่อเก็บสถานะของแอปพล

อ่านต่อไป →

reactjs - อาร์กิวเมนต์ประเภท 'React.ReactInstance' ไม่สามารถกำหนดค่าให้กับพารามิเตอร์ประเภท 'React.ReactInstance' ได้

ฉันได้รับข้อผิดพลาดดังต่อไปนี้ในคอมโพเนนต์ React ขณะพัฒนาด้วย TypeScript:

Argument of type 'React.ReactInstance' is not assignable to parameter of type 'React.ReactInstance'. Type 'Component<any, {}>' is not assignable to type 'ReactInstance'. Type 'React.Component<any, {}>' is not assignable to type 'React.Component<any, {}>'. Two different types with this name exist, but they are unrelated.

นี่คือโค้ด (หวังว่าส่วนที่เกี่

อ่านต่อไป →

javascript - เกิดข้อผิดพลาดใน [at-loader] ./node_modules/@types/react-router-dom/index.d.ts:43:42

ฉันติดตั้ง react-router-dom ลงในเว็บไซต์ react-redux ที่ใช้ typescript ของฉันแล้ว ตอนนี้ฉันพบข้อผิดพลาดตามชื่อเรื่องของหัวข้อของฉัน, package.json ของฉัน:

{ "name": "typescript-webpack-react-flux-boilerplate", "version": "1.0.0", "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/pepaar/typescript-webpack-react-flux-boilerplate.git" }, "scripts": { "start": "node se

อ่านต่อไป →

reactjs - ไม่สามารถหา namespace ของ react-uwp ได้เมื่อคอมไพล์ TypeScript

ฉันใช้เครื่องมือ create-react-app พร้อมกับสคริปต์ typescript เพื่อสร้างโปรเจกต์ react เริ่มต้นโดยใช้ typescript จากนั้นฉันพยายามเพิ่ม react-uwp โดยใช้ npm (--save) มันติดตั้งได้เรียบร้อยและอยู่ในโฟลเดอร์ node_modules ของฉัน ฉันได้แก้ไขไฟล์ tsconfig.json ของฉันตามที่หน้าการเริ่มต้นใช้งานสำหรับ react-uwp ระบุ (ที่นี่: https://www.react-uwp.com/Get-Started)

มีสองตัวเลือก:

  1. เพิ่มโฟลเดอร์โมดูล react-uwp ไปยัง 'typeRoots'
  2. เพิ่ม 'index.d.ts' จากโฟลเดอร์ react-uwp ไปยังส่วน 'i

    อ่านต่อไป →

reactjs - สืบทอดคอมโพเนนต์ของ react ด้วย mobx

ฉันมีคอมโพเนนต์ที่สืบทอดจากคลาสนามธรรมและใช้ตัวตกแต่งของ mobx แบบนี้:

@inject("matrixStore") @observer export default class DayRow<T extends IAbstractRowProps = IAbstractRowProps> extends AbstractRow<T> { // ... }

ฟังก์ชัน render อยู่ในคอมโพเนนต์ AbstractRow เอง

ฉันสืบทอดจาก DayRow พร้อมกับคอมโพเนนต์อื่น:

@inject("matrixStore") @observer export default class DayFinderRow extends DayRow<IDayFinderRowProps> { }

อ่านต่อไป →

react dnd - ตัวอย่าง ReactDnd TypeScript

มีตัวอย่างมากมายออนไลน์ที่ใช้ไวยากรณ์ของ Babel ฉันได้ลองใช้แล้ว แต่ส่วนใหญ่ไม่สามารถใช้งานร่วมกับ Typescript 2.1 ได้

อ่านต่อไป →

javascript - ฉันจะเขียนการกำหนดประเภทสำหรับคลาสย่อย (React.Component) ใน TypeScript ได้อย่างไร?

ฉันกำลังพยายามหาวิธีเขียนคำจำกัดความประเภทสำหรับ react-highlight (คลาส Highlightable ดูที่นี่) เพื่อ ขยาย Highlightable และเพิ่มฟังก์ชันการทำงานที่กำหนดเอง เนื่องจากคลาส JS ดั้งเดิมของ Highlightable เป็นซับคลาสของ React.Component ฉ

อ่านต่อไป →

typescript - ใช้คอนโทรลฟอร์มของ primeng และ reactive forms ของ angular จะสามารถดึงค่าของ dropdown ได้อย่างไร

ฉันมีคอมโพเนนต์ dropdown ของ primeng....

<form [formGroup]="skillsForm"> <p-dropdown [options]="experienceList" optionLabel="name" formControlName="example" ></p-dropdown> </form>

ลึกลงไปภายในกลุ่มฟอร์มที่ซ้อนกันและอาร์เรย์ ดังนั้นฉันต้องใช้ฟอร์มเชิงปฏิกิริยา

ฉันพยายามที่จะรับค่าของตัวเลือกโดยใช้

skillsForm.value.example

และรับสิ่งของนั้น

{name: 'Over a year', value: '1.0'}

อ่านต่อไป →