New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: does not work onChange Event #479
Comments
It is because the fresh uses preact. Sadly, there are some differences between React and Preact.
These two differences can occur a bug like this :(, If you want to avoid this, you can use |
So, If you want to get an expected behavior, you have to write the code like this. /** @jsx h */
import { h } from 'preact';
import { tw } from '@twind';
import { useState } from 'preact/hooks';
import { IS_BROWSER } from '$fresh/runtime.ts';
interface InputProps {}
const Input = ({}: InputProps) => {
const [state, setState] = useState('aa');
const update = (e: any) => {
setState('testtt'); // this will update the state, but sadly the state will not affect to the input value.
+ e.target.value = 'testtt'; // so you have to change the value directly
};
return (
<input
+ onInput={update} // onChange → onInput
value={state}
placeholder="test"
disabled={!IS_BROWSER}
></input>
);
};
export default Input; |
Wow, Thank you so much. |
Is something as changed since? Do Fresh uses |
this code is Input component in islands folder
In my opinion, when it is entering the input component, the input value should be fixed as 'test' while the onChange event occurs
That's how it works in react
but in fresh framwork, it does not work this way
in fresh, it works like this video
so I was wondering why fresh framework works this way ?
ps. Although I removed
disabled={!IS_BROWSER}
, it still did not workThe text was updated successfully, but these errors were encountered: