小编Ami*_*avi的帖子

使用 Typescript [react-navigation v6] 在嵌套导航器中获取路由参数时出现类型错误

导航类型定义如下,当我从 例如 导航AOne到时BTwo,控制台id:99 日志props.route.params显示正确的信息。但props.route.params.id抛出类型错误

类型错误:未定义不是对象(正在评估“props.route.params.id”)

    // navigation related imports in all components 
    import {BottomTabScreenProps} from '@react-navigation/bottom-tabs';
    import {CompositeScreenProps, NavigatorScreenParams} from '@react-navigation/core';
    import {StackScreenProps} from '@react-navigation/stack';

    // type defenitions
    export type StackOneParams = {
      AOne:undefined,
      BOne: undefined,
      // some other screens
    };
    export type StackTwoParams = {
      ATwo: undefined;
      BTwo:{id:number};
      // some other screens
    };
    
    export type TabParams = {
      StackOne: NavigatorScreenParams<StackOneParams>;
      StackTwo: NavigatorScreenParams<StackTwoParams>;
    // ... some other stacks each represent a …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation react-navigation-stack react-navigation-bottom-tab react-navigation-v6

11
推荐指数
1
解决办法
4548
查看次数

使用YAML在本地构建Azure DevOps管道

在将其推送到分支以测试可能的错误之前,如何在本地计算机上模拟Azure Devops管道的构建过程.

解决方案在本地构建正确,没有错误和警告.还从VS命令行MSBuild编译没有错误的解决办法,但在某些试图推动管道建设引发许多错误大多与preprocessor defenitionprecompiled header.

我想知道如何在我的机器上本地测试相同的过程,而无需推送回购.

azure-pipelines.yml
-------------------
pool:
  vmImage: 'vs2017-win2016'

steps:
- task: MSBuild@1
  displayName: 'Build solution'
  inputs:
    platform: 'Win32'
    configuration: 'release'
    solution: 'mysolution.sln'
- task: VSTest@2
  displayName: 'Run Test'
  inputs:
    platform: 'Win32'
    Configuration: 'release'
    testAssemblyVer2: |
     **\*.Test.dll
     !**\*TestAdapter.dll
     !**\obj\**
    runSettingsFile: project.Test/test.runsettings
    codeCoverageEnabled: true 
Run Code Online (Sandbox Code Playgroud)

visual-c++ azure-devops azure-pipelines

9
推荐指数
1
解决办法
3036
查看次数

反应:写入 json 文件或导出/下载 [无服务器]

我真的对 JS/TS 中的文件 I/O 感到困惑。我看到的大多数示例都适用于 DOM 并且具有基于浏览器的解决方案。

另外,我不明白如何fs工作,它似乎需要一个 webpack 配置,我使用 CRA 并且不想弹出。

在 React 组件中,我想从服务器获取一些数据,然后将它们作为 JSON 文件保存在项目文件夹中(相同的路径、根、公共文件夹,无论)或直接下载(不需要按钮)。

//data type just in case
inteface IAllData{ name:string; allData:IData[];}
Run Code Online (Sandbox Code Playgroud)

所以在获取一些数据后想要将它们保存到 name.json

public componentDidMount(){
   this.fetchData().then(()=>this.saveData())
}

public async fetchData(){/* sets data in state*/}

public saveData(){
    const {myData}=this.state;
    const fileName=myData.name;
    const json=JSON.stringify(myData);
    const blob=new Blob([json],{type:'application/json'})
    /* How to write/download this blob as a file? */
}
Run Code Online (Sandbox Code Playgroud)

在这里尝试window.navigator.msSaveOrOpenBlob(blob, 'export.json');没有用

注意:我知道它有安全风险,它不适用于生产。首选将文件保存在项目文件夹中,但下载完全没问题。

javascript file-io blob reactjs

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

C++,使用 nlohmann::json 解析 JSON 数组

在导入到我的 C++ 程序中的 json 文件中,结构如下:

{
 "a":"1",
 "ec":[
       {
        "a":"0x00",
        "s":[
             {"a":"0xA0"},
             {"a":"0xA1"},
            ],
        "b":"v1"
       },
       {
        "a":"0x01",
        "s":[
             {"a":"0xB0"},
             {"a":"0xB1"},
            ],
        "b":"v2"
       }
      ]
}
Run Code Online (Sandbox Code Playgroud)

我想迭代"ec"数组并获取所有数组的值,"a"并且每个数组"a"的值都相同s

vector<string> ec_a; // should contain {"0x00","0x01"}
vector<string> a1_s; // should contain {"0xA0", "0xA1"}
vector<string> a2_s; // should contain {"0xB0","0xB1"}
Run Code Online (Sandbox Code Playgroud)

首先我得到了大小,ec但从我理解的文档中应该使用迭代器来完成其余的工作

int n=j["ec"].size() // n = 2
for(auto it=j["ec"].begin();it!=j["ec"].end();++it){
  if(it.key() == "a") ec_a.push_back(it.value());
}
Run Code Online (Sandbox Code Playgroud)

但得到这个例外nlohmann::detail::invalid_iterator at memory location 我认为这j["ec"].begin()是不正确的。

我该怎么做,谢谢。

c++ json nlohmann-json

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

创建 React App 找不到声明的模块

我有一个用 CRA 打字稿创建的项目。

在项目的根目录中存在tsconfig.json一个名为types. 在类型文件夹中,我modulename.d.ts为在 node_modules 没有默认类型的模块创建了一个文件,并且在@types\module-name.

但我在编译时收到错误。

类型错误:找不到模块“thename”的声明文件。'/*/node_modules/thename/dist/entry.js' 隐式具有 'any' 类型。

为什么编译器在 types 文件夹中找不到类型声明?

// .d.ts
declare module 'foo-react' {
    import * as React from 'react';
    // ...
}
Run Code Online (Sandbox Code Playgroud)

这是 tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": { "*": ["types/*"] },
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "plugins": [{ "name": "typescript-tslint-plugin" }],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig typescript-typings create-react-app react-tsx

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

如何重置嵌套导航器 (react-navigation v5)

有两组堆栈导航器;

const SetOneScreens = () => (
  <Stack.Navigator initialRouteName="AScreen">
    <Stack.Screen name="AScreen" component={AScreen} />
    <Stack.Screen name="BScreen" component={BScreen} />
  </Stack.Navigator>
);
const SetTwoScreens = () => (
  <Stack.Navigator initialRouteName="CScreen">
    <Stack.Screen name="CScreen" component={CScreen} />
    <Stack.Screen name="DScreen" component={DScreen} />
  </Stack.Navigator>
);
Run Code Online (Sandbox Code Playgroud)

哪些嵌套在抽屉导航器中

    <NavigationContainer>
      <Drawer.Navigator initialRouteName="SetOneScreens">
        <Drawer.Screen name="SetOneScreens" component={SetOneScreens} />
        <Drawer.Screen name="SetTwoScreens" component={SetTwoScreens} options={{swipeEnabled: false}} />
      </Drawer.Navigator>
    </NavigationContainer>
Run Code Online (Sandbox Code Playgroud)

我想从导航BScreenDScreen并重置堆栈(为了不让android中的硬件后退按钮返回BScreen

在嵌套的情况下,我们应该首先定义导航器名称;我应该如何在重置操作中定义屏幕。

// For navigation 
props.navigation.navigate('setTwoScreens',{screen:'DScreen'})

// For reset I can only navigate to initial screen 
props.navigation.reset({index:0,routes:[{name:'setTwoScreens'}]})
Run Code Online (Sandbox Code Playgroud)

我应该如何处理resetwithnavigation …

reactjs react-native react-navigation react-navigation-stack react-navigation-v5

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

Graphviz,无法识别 gvpr

我正在尝试使用MaDGe使用 CLI 命令将依赖关系图另存为 SVG 图像

madge --image graph.svg path/src/app.js
Run Code Online (Sandbox Code Playgroud)

但我面临错误 'gvpr' is not recognized as an internal or external command

这是我C:\Program Files (x86)\Graphviz2.38\bin在 PATH 中的位置。

我也尝试在用户和系统变量中添加 PATH 但仍然是同样的问题

svg graphviz system-variable madge

6
推荐指数
1
解决办法
1417
查看次数

React Hooks和jsx-no-lambda警告

因此,现在我们不能将挂钩用作事件函数的旧样式,除了禁用警告之外,调用不违反规则的事件函数的最佳方法是什么

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}> // Lambdas are forbidden in JSX attributes due to their rendering performance impact (jsx-no-lambda)
        Click me
      </button>
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

reactjs tslint react-tsx

6
推荐指数
1
解决办法
2204
查看次数

React Hooks (useState) 和 Mobx [没有 mobx-react-lite]

在我的 React 应用程序(带有打字稿)中,我想使用 React 钩子(特别是 useState)来管理表单状态,同时将其用作 Mobx 商店的可观察组件,但出现错误

钩子只能在函数组件的主体内部调用。

所以例如在以下组件中

import * as React from "react";
import { inject, observer } from "mobx-react";
import { MyStore } from "./MyStore";

interface IProps {
  myStore?: MyStore;
  id: string;
}

const MyComponent: React.FC<IProps> = props => {
  const [state, setState] = React.useState("");
  return (
    <div>
      <h1>{props.id}</h1>
    </div>
  );
};
export default inject("myStore")(observer(MyComponent));
Run Code Online (Sandbox Code Playgroud)

我看到了一个解决方案,但它React.createContext用于导出商店类。是不是 Mobx 和 Hooks 的旧方法?

这是示例的沙盒

reactjs mobx mobx-react react-tsx react-hooks

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

带 3 卡分页布局的 React-Native FlatList

这个小吃中,我尝试在屏幕中央放置 3 张卡片,并使用水平 FlatList 并启用分页以跳转到滚动时的下 3 张卡片。

\n

但是布局在滚动后开始被破坏,并且下一张/上一张卡片的一些像素出现在视图中。

\n

我应该如何设置此列表的样式,使其始终在屏幕中央恰好有 3 张卡片,并且滚动将跳转到包含接下来 3 张卡片的下一页?或者像 GooglePlay 商店一样,上一张/下一张卡片的固定像素在主 3 张卡片的左侧和右侧可见。(下面的示例截图)

\n
 <View style={{flex:1,justifyContent: \'center\', marginLeft: 5, marginRight: 5,}}>\n      <FlatList\n        horizontal\n        pagingEnabled\n        data={data}\n        keyExtractor={(item) => `\xc3\xactem-${item}`}\n        renderItem={({ item }) => (\n          <Card style={{width:Dimensions.get("window").width/3-5,marginRight:5}}>\n            {/* some content */}\n          </Card>\n        )}\n      />\n </View>\n
Run Code Online (Sandbox Code Playgroud)\n

我不需要像snap-carousel这样的图书馆......

\n

在此输入图像描述

\n

react-native react-native-scrollview react-native-flatlist react-native-stylesheet

6
推荐指数
1
解决办法
8728
查看次数