Questions tagged [preact]

Used for questions related to Preact, a fast 3kb alternative to React.

Preact is a fast 3kb alternative with the same API

Related links

524 questions
51
votes
1 answer

Wrong components rendered by Preact

I'm using Preact (for all intents and purposes, React) to render a list of items, saved in a state array. Each item has a remove button next to it. My problem is: when the button is clicked, the proper item is removed (I verified this several time),…
Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159
47
votes
2 answers

Jest expect.any() not working as expected

So when testing one of my reducers in a Preact(not much different to React while testing with JEST) based project, I got bumped into this issue: Following output comes up when running jest test - ● should setup …
rupav jain
  • 645
  • 1
  • 7
  • 13
21
votes
6 answers

Is there any Yarn equivalent of npx preact create?

I am trying to run the preact create command using Yarn. It's simple to run preact create ..... ..... or npx preact create ... ..... It works fine and both of the commands use npm. But I am trying to run the command using Yarn. I have tried the…
user12987437
17
votes
2 answers

import { h } from preact - when is it necessary

I'm currently building a Preact PWA with the CLI. My understanding was that wherever I have a component defined with JSX, I need to have import { h } from 'preact' at the top of the file. I removed all instances of that import statement, yet the…
dgb_nz
  • 231
  • 2
  • 11
14
votes
4 answers

How to use React Router with Preact

I'm using Preact as my View framework (can NOT use React due to the Facebook IP problems). I needed to use React Router for the location routing because it has more flexibility than the Preact Router that the same team built. I managed to get React…
TbWill4321
  • 8,626
  • 3
  • 27
  • 25
13
votes
4 answers

Using web-components within Preact and typescript

I'm using custom-elements aka web-components within Preact. The problem is that Typescript complains about elements not being defined in JSX.IntrinsicElements - in this case a check-box element:
Simon
  • 2,686
  • 2
  • 31
  • 43
12
votes
3 answers

Jest tests on React components: Unexpected token "<"

Trying to set up Jest to test my React components (Technically I'm using Preact) but same idea... Anytime I try to get a coverage report, I get errors when it hits any jsx syntax. Error Running coverage on untested files...Failed to collect coverage…
Eli Nathan
  • 1,020
  • 2
  • 13
  • 35
11
votes
1 answer

How does react trigger componentDidMount with safari cache?

React 16 triggers componentDidMount() when going back in Safari, even tho the component never unmounted. How does react know when to mount? class Foo extends React.Component { state = { loading: false } componentDidMount() { // when…
oshell
  • 8,923
  • 1
  • 29
  • 47
11
votes
2 answers

How are "refs" handled in Preact?

React has the concept of refs. Is there a similar concept in Preact that can be used without preact-compat? I want to be able to reference elements in Component methods without a DOM look-up. Thanks!
Donald T
  • 10,234
  • 17
  • 63
  • 91
10
votes
2 answers

How to programmatically navigate with preact-router?

I'm trying to figure out how to structure the frontend part of a web application using typescript, preact and preact-router. I've come a long way but I still need to figure out how to programmatically navigate (redirect) with preact-router. I can do…
David Nordvall
  • 12,404
  • 6
  • 32
  • 52
9
votes
1 answer

Uncaught TypeError: Cannot read properties of undefined (reading '__H')

I'm trying to build a simple Todo App using Preact + Vite + Typescript + Redux. But I am facing some compatibility issues with redux and typescript. This is the error I'm getting. Uncaught TypeError: Cannot read properties of undefined (reading…
Vivek Kaushik
  • 261
  • 1
  • 2
  • 5
9
votes
2 answers

Set Base URL for Preact CLI

Using Preact CLI is it possible to set the path where the app will be hosted outside of the root directory? For instance hosting the app at http://mywebsite.com/relativepath/index.html
Tim Arney
  • 1,776
  • 2
  • 18
  • 23
8
votes
2 answers

node_modules/preact/src/jsx.d.ts:2145:22 - error TS2304: Cannot find name 'SVGSetElement'

I am experiencing this build error since last two days (Angular App). Error: node_modules/preact/src/jsx.d.ts:2138:24 - error TS2304: Cannot find name 'SVGMPathElement'. 2138 mpath:…
8
votes
2 answers

(p)React avoid unnecessary rerender on submit

When focused in the input box, hitting enter submits the form. On submit, an error causes an error to be inserted into the state which causes a rerender and creates a new element to show the error. {error &&
{error}
} This rerenders the…
david_adler
  • 9,690
  • 6
  • 57
  • 97