问题标签 [preact]

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 投票
3 回答
3423 浏览

reactjs - 流:解构。React/Preact 中缺少注释

刚刚开始使用 Flow 但似乎无法理解它想让我做什么来添加类型来解构对象,例如道具

IE

抛出一个错误,如

当我添加注释时它仍然抱怨

如果有人能指出,我显然在这里遗漏了一些非常简单的东西吗?

0 投票
0 回答
329 浏览

javascript - Preact 生命周期(redux 状态和 componentWillReceiveProps)

我有一个关于 Preact 生命周期的问题。我创建了一个非常接近我的业务用例的 jsfiddle。用例结合了 HOC、redux 和 Preact 生命周期。用例背后的想法很简单!我创建了一个红色的拖动表面,在拖动结束时,我想在减速器中切换一个值!我很惊讶即使mapStateToProps被调用,当我在下一个componentWillReceiveProps刻度中记录标志的值时,标志仍然没有切换。以下是来自以下 js fiddle https://jsfiddle.net/4yzLdtkd/32/的日志 component will receive props: isDragging component will receive props: hasDragged map state to props false component will receive props: value = true component will receive props: value = false

我用 react 创建了完全相同的用例,结果不同。标志是直接切换的。以下是来自以下 js fiddle http://jsfiddle.net/urkuwnLr/9/的日志 component will receive props: isDragging component will receive props: hasDragged map state to props false component will receive props: value = false

这是一个错误还是 Preact 在生命周期方面与 React 的工作方式略有不同?

0 投票
2 回答
1040 浏览

javascript - 将 UglifyJS 与 Preact、Webpack 2 一起使用时出现意外的令牌错误

我正在使用 Preact/ES6/Webpack 构建一个 Chrome 扩展。我使用 2 种配置之一进行打包:debug使用 ESLint、Babel 和 CSS + JSON 加载器,prod添加 2 个插件:UglifyJS和 Zip。这是webpack.config.js

但是当我运行时prod,我得到以下错误:

值得一提的getLatestResults是,这并不是我的代码中唯一在await它前面的函数。此外,它应该只出现在background.js其他入口点不应该调用它的情况下。

另外值得一提的是,如果我只是对UglifyJS代码进行注释,生成的压缩扩展名效果很好。

我缺少什么配置来使这些错误消失?

0 投票
1 回答
459 浏览

javascript - 代码拆分 React 组件

我对 React 相对较新(准确地说,我使用的是 preact.js),并且我正在尝试使用 webpack 2 对 react 组件进行代码拆分。

我按照文档中的说明导出我的组件,然后importing加载它。

脚本加载,但我没有正确处理承诺回调,并且发现很难看到任何显示工作版本的文档。

List返回以下对象:

在此处输入图像描述

0 投票
1 回答
212 浏览

reactjs - React-Router-v4 无法通过 Babel Register 处理 Preact

我正在尝试使用 react-router-4 设置服务器渲染反应。虽然它在前端(Webpack)上工作得很好。在服务器端使用时似乎preact-compat不起作用。我正在使用babel-register转换代码。

图片

我这里有一个分支供参考: https ://github.com/abrcenas29/preact-sandbox-v0/tree/wip/isomorphic-react

跑步: yarn run install yarn run start:prod

localhost:3100

0 投票
1 回答
1835 浏览

reactjs - 无法设置 # 的属性 createElement which is only a getter

Description

What you are reporting: I am following this set of instructions on how to

Description

What you are reporting: I am following this set of instructions on how to setup React hot loarder. But when I go to step 3 where I put the patch, it breaks in to the one below.

Expected behavior

What you think should happen: Should work properly

Actual behavior

image

Environment

React Hot Loader version: next

Run these commands in the project folder and fill in their results:

  1. node -v: 7.9.0
  2. npm -v: 4.2.0

Then, specify:

  1. Operating system: Windows 10
  2. Browser and version: Latest Chrome

Reproducible Demo

https://github.com/abarcenas29/preact-sandbox-v0/blob/wip/hot-reloader/src/main.js

branch: wip-hot-reloader

Instructions:

  • yarn
  • yarn run postinstall
  • yarn run start:dev

Route users to different paths according to information entered in rails

My userinfos controller handles user information. As soon as the user signs up, I want them to go to the page that lets them fill out the user information like name, email, gpa, college...Lets just say they leave before completing the form, when they sign in again, I want to check if the user information has been filled out, if not, I want to take them to enter the new information page. To do this, I added the "info_complete" function to my userinfo model(as shown below). Here are my two models which will tell you the relationship between them.

Userinfo model:

User model:

Then I added the following code to the application controller. My application controller:

When I try to log in after saving this, I get the following error:enter image description here

Full error trace:

Any help is appreciated. Thanks!

0 投票
1 回答
590 浏览

javascript - how to create preact-cli custom production build

I'm now studying preact-cli and so far, it's working though. Problem is when we're gonna build for production, there is zero-configuration for it and found no works for api caching. Is there anyone who has had experience about it, please let me know. Thanks.

0 投票
3 回答
4932 浏览

reactjs - 反应将类添加到元素

我正在尝试向元素添加类名,但它不起作用。我是否缺少 JSX 组件的某些内容?

0 投票
1 回答
1532 浏览

reactjs - Preact 映射数据数组

我正在构建一个组件,它将动态列出接下来的三个会议日期。在组件内部,当我 console.log 时 props 变量映射数组中的每个字符。控制台日志中的第一行是 getMeetingDates 函数返回的内容

在此处输入图像描述

这是渲染

难道我做错了什么?

0 投票
1 回答
1953 浏览

reactjs - 如何创建具有 HTMLAttributes 作为道具的组件

我正在使用 Typescript 和 Preact。我想创建一个组件来公开 a<span/>可以拥有的所有道具:

但是,上面的示例使用了any,这并不是真正的类型安全。相反,我想公开属性span