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

359 questions
43
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
  • 24,425
  • 20
  • 100
  • 145
24
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
  • 387
  • 1
  • 3
  • 11
14
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
  • 191
  • 1
  • 9
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
  • 7,509
  • 1
  • 24
  • 42
11
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,098
  • 2
  • 21
  • 22
9
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 Taylor
  • 8,894
  • 15
  • 59
  • 85
9
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
  • 10,394
  • 5
  • 28
  • 46
8
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
  • 1,924
  • 23
  • 34
8
votes
1 answer

Cannot set property createElement of # which is only a getter
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…
Mr A
  • 1,205
  • 4
  • 19
  • 49
7
votes
2 answers

Error with JSX in my React Library when Switching to Preact

I have a really simple React library that I use with my own state management. It's just a Higher Order Component: import React from 'react'; /** * * @param {Object} state - Reference to SubState instance * @param {Object} chunk - object of…
Tamb
  • 600
  • 6
  • 16
7
votes
1 answer

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,516
  • 2
  • 14
  • 20
6
votes
1 answer

Is mixing bundled modules and JavaScript Modules possible

Inspired by preact's "no build tools route", I recently created a project with no build or bundling process. Conceptually, it looks like this (pseudo code following). I have a dependency on react-button which uses e.g. microbundle to resolve the…
Tim Daubenschütz
  • 1,676
  • 4
  • 19
  • 37
6
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
  • 5,354
  • 4
  • 39
  • 64
6
votes
1 answer

Using React Dev Tools with Preact

I have just got preact-redux-example up and running, and now I am attempting to use Preact Dev Tools in my app. Based on this post I assumed it was a case of adding import 'preact/devtools' into the entry point (app.js) file. However, this yields…
alanbuchanan
  • 3,225
  • 4
  • 30
  • 58
5
votes
2 answers

How to convert create-react-app to Preact?

As per Preact documentation, to convert a React app to Preact you have to alias webpack: { "resolve": { "alias": { "react": "preact-compat", "react-dom": "preact-compat" } } } How can you do this with create-react-app since…
zenlight
  • 63
  • 1
  • 6
1
2 3
23 24