TextInput组件突然在生产环境中不起作用,使用Laravel 10和Reactjs。

huangapple go评论119阅读模式
英文:

TextInput Component suddenly not working in production Laravel 10 Reactjs

问题

我遇到了laravel reactjs的TextInput组件的奇怪问题。

我从laravel breeze reactjs获取了这个组件。
问题是我无法在<TextInput>上键入任何内容,但如果我将其更改为<input>标签,它可以正常工作。直到今天,<TextInput>突然停止工作,我没有更改任何内容,因为它是laravel自带的,在本地开发中,除了我没有在本地运行npm run build之外,它完全相同。

我已经运行了npm run build并重新启动了ssr服务器,但没有运气。

以下是Login.jsx中的一个TextInput示例:

<TextInput
    id="email"
    type="email"
    name="email"
    value={data.email}
    className="mt-1 block w-full"
    autoComplete="username"
    isFocused={true}
    handleChange={onHandleChange}
/>

如果我更改为这个input,它可以正常工作:

<input
    type="email"
    name="email"
    id="email"
    value={data.email}
    className="border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm mt-1 block w-full"
    autoComplete="username"
    required
    onChange={onHandleChange}
/>

通过对组件文件TextInput.jsxCheckBox.jsx(也出现了问题)进行任何更改,然后再次运行npm run build,组件似乎又可以正常工作。

有什么想法是出了什么问题?

英文:

I got weird problem with TextInput Component from laravel reactjs.

I got the component from laravel breeze reactjs.
The problem is I cant type anything on the &lt;TextInput&gt;, but if i change it to <input&gt; tag it works fine. It was working fine till today suddenly &lt;TextInput&gt; stop working, I didnt change anything because it comes with laravel and it works fine in local development exactly same code except I didnt do npm run build on local.

I already did npm run build and restart ssr server, no luck.

Here is one of the TextInput from Login.jsx

&gt; &lt;TextInput
&gt;    id=&quot;email&quot;
&gt;    type=&quot;email&quot;
&gt;    name=&quot;email&quot;
&gt;    value={data.email}
&gt;    className=&quot;mt-1 block w-full&quot;
&gt;    autoComplete=&quot;username&quot;
&gt;    isFocused={true}
&gt;    handleChange={onHandleChange}
&gt; 
&gt; /&gt;

If I change it to this input, it works

&lt;input
    type=&quot;email&quot;
    name=&quot;email&quot;
    id=&quot;email&quot;
    value={data.email}
    className={
    &#39;border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm mt-1 block w-full&#39;
    }
    autoComplete=&quot;username&quot;
    required
    onChange={onHandleChange}
/&gt;

It seems the component works again by making any changes to the component files, TextInput.jsx and CheckBox.jsx (was broken too). then run npm run build again.

Any idea what went wrong?

答案1

得分: 2

我今天也遇到了同样的问题,解决方法是在 TextInput.jsx 中将 ref 从:

ref={localRef}

改为:

ref={input}
英文:

I was facing the same issue today and solve it changing ref in TextInput.jsx

from:

ref={localRef}

To:

ref={input}

huangapple
  • 本文由 发表于 2023年2月23日 22:58:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546536.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定