问题标签 [reason-react]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
93 浏览

reactjs - 为什么类型声明的位置很重要?

ReasonReact的文档指定应该在代码中声明类型的位置:

状态类型可以是任何东西!一个 int、一个字符串、一个 ref 或公共记录类型,您应该在调用之前声明它们:reducerComponent

重点是他们的。

为什么类型声明的位置很重要,只要它是有效的?只有当两条线相邻时才会进行某种优化?如果我在它们之间插入其他东西或将它们放在单独的模块中会发生什么?

0 投票
1 回答
892 浏览

javascript - 如何在 ReasonML 中扩展 JS 类

例如,我有一个类似 es6的类:

class Foo {...}

我想扩展它:

class Bar extends Foo {...}

reason-react文档中,我找到了示例,但我不确定它是否适合我:

但是当我尝试用这种风格编写代码时,我得到一个错误:

错误:未绑定记录字段更新

(在这个例子mysuperclass中是来自 3rd-party js-library 的外部)。

也许我做错了什么?

0 投票
1 回答
223 浏览

reason - 在 ReasonReact 中找不到 reducerComponent

我正在尝试按照这个Reason React 教程来构建一个简单的 TodoApp:

但是,当将组件的类型从更改为时statelessComponentreducerComponent出现以下错误:

0 投票
1 回答
498 浏览

material-ui - 如何在原因反应绑定中跨组件组合道具?

我目前正在编写一个材料 UI 原因反应绑定,我想知道如何重用以前定义的道具。

Select 组件在底层 react-js 库中将所有 Input props 传播到自身中。这是通过传播道具来完成的,但是在 ReasonML 中不鼓励这样做,因为类型会丢失。

作为临时解决方案,我已经将道具从一个复制到另一个,但这不可扩展。如果有人能建议在 Reason-React 中这样做的正确方法是什么,我将不胜感激?

谢谢

输入模块定义:

选择模块定义:

0 投票
2 回答
592 浏览

ffi - 如何使用reason-react定义一个在函数签名中接受多种类型的绑定?

在定义一个原因反应绑定时,我想知道如何确定一个接受多种类型的绑定。例如,我有一个应该接受的参数~valuestringnumber或。目前我正在使用,但我认为这不是最干净的方法,因为我更愿意明确定义类型。如何才能做到这一点?我看过但我不确定如何将外部语法组合到函数签名中。array(string)array(number)option('a)bs.unwrap

作为一个附带问题,由于未定义数字类型,我的绑定是否也必须将浮点数和整数映射为数字?

0 投票
2 回答
248 浏览

ocaml - Graphql 数组对 ReasonReact 的响应

试图以合理的方式处理数据。我有这个 graphql 查询返回数据并记录它。问题是如何访问以下组件中的数据。

这是查询响应: 在此处输入图像描述

来自 JS 我一直想用一些类似 response.data 的方式记录 allEpisodes ......这显然在这里不起作用

组件的要点:剧集组件home.re 组件

如果我取消注释并运行,它会产生以下错误:

```

```

我不明白在返回数组时如何处理响应对象。谢谢你。

根据@glennsl 的建议更新:

这会产生以下错误:

在此处输入图像描述

我正在考虑它的到来,因为类型没有被传递给 episode.re

我应该在某处传递列表(剧集)吗?

更新 2:感谢@glennsl,这段代码可以在 JSX 上运行

0 投票
1 回答
588 浏览

ocaml - Understanding ReasonML/Bucklescript Externals

Just trying to generally understand what is going on here. Does this make sense to explain ReasonApolloTypes.gql as an example of using Externals.

This is the bs.module code

[@bs.module] external gql : ReasonApolloTypes.gql = "graphql-tag";

bs.module tells buckelscript that we want to use a FFI.

external tells bs the name of the FII we want to use and we set its value to ReasonApolloTypes.gql which is a globally available Reason module that we installed when we added reason-apollo in bsconfig's bs-dependencies array, and to package.json. If you open node_modules/reason-apollo/src you will see defined Reason modules that are globally available like any other.

ReasonApolloTypes.re is listed there and contains a defined type named gql. So ReasonApolloType.gql is the named module we are accessing with external gql. In ReasonApolloType.gql there is a defined type, type gql = [@bs] (string => queryString);. This tell bucklescript to assign a type of string to the gql type and the assign the value to querystring, so type querystring is of type string. Then set ReasonApolloTypes.gql to use the "graphql-tag" node library to resolve ReasonApolloTypes.gql.

Am I missing an concepts here? Is this expressed correctly? The Bucklescript/Reason docs are above my head for Externals at this point. Thanks.

0 投票
2 回答
489 浏览

reactjs - 如何将自定义方法添加到 ReasonReact 组件?

我对 ReasonML 很陌生。我能够使用 ReasonReact 成功创建无状态组件,但我还没有弄清楚如何向组件添加自定义方法(例如Next.js' staticgetInitialProps)。

尝试getInitialProps在组件上定义方法时,我收到一个The field getInitialProps does not belong to type ReasonReact.componentSpec错误。

我应该如何在 React 组件上添加这个定义这个自定义方法?

零件

错误

0 投票
1 回答
148 浏览

reason - 是否可以在回调函数中使用reduce?

我有这个简单的组件

我正在尝试像这样使用它

但我得到这个错误就onChange行了

我想我理解这个错误,但我不知道要修复它。我也这样onChange定义

但这次我得到

你知道如何解决它吗?是否可以reduce在另一个回调函数中调用?

0 投票
1 回答
464 浏览

dom - 在 React 组件中聚焦输入字段 - 尝试创建 ref 时出现类型错误

我有一个包含文本<input>元素的 React 组件。安装组件后,我希望在输入字段中设置文本光标,即我希望文本输入元素具有焦点。

在“传统”的 JavaScript React 组件中,我会通过 ref 获取输入字段的 DOM 元素,然后调用它的focus方法。

我已经阅读了解释如何在 Reason-React 中使用 refs 的文档:https ://github.com/reasonml/reason-react/blob/master/docs/react-ref.md

唉,这个页面上包含的代码示例是针对自定义组件的引用,它只提到它也适用于 React DOM 元素。

所以我尝试将示例代码转换为 React DOM 元素,这是我迄今为止尝试过的:

我得到的错误信息是这样的:

我知道问题可能在于我如何在代码开头定义状态类型,DOM 元素与自定义组件不同。

在这里修复错误的正确类型定义是什么?

完整的项目可以在 GitHub 上找到:https ://github.com/pahund/todo-list-reason-react/tree/ref-problem