Skip to content
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

Module Parse Failed for HSPinInput.getInstance #395

Open
jimmyzzxhlh opened this issue Jun 18, 2024 · 2 comments
Open

Module Parse Failed for HSPinInput.getInstance #395

jimmyzzxhlh opened this issue Jun 18, 2024 · 2 comments

Comments

@jimmyzzxhlh
Copy link

jimmyzzxhlh commented Jun 18, 2024

Summary

Preline 2.3.0 throws Module Parsed Failed if I tried to call HSPinInput.getInstance()

Steps to Reproduce

I'm trying to get the pin input object using HSPinInput.getInstance in NextJS, but got the following error for Preline 2.3.0.

Module parse failed: Unexpected token (22:21)
| 
| class HSAccordion
> 	extends HSBasePlugin<IAccordionOptions>
| 	implements IAccordion
| {

I'm not sure if I'm doing it in the right way to get the pin item instance object, because I got a different error in older version of Preline (e.g. 2.0.3 from the demo Stackblitz) which basically returns me a null object. What is the best way to get the pin value in this case?

Demo Link

https://stackblitz.com/edit/preline-v2-nextjs-tvm16z?file=src%2Fapp%2Fcomponents%2FPinInputItem.tsx

Expected Behavior

No response

Actual Behavior

No response

Screenshots

No response

@Jiroscopes
Copy link

Make sure your import is like import { HSPinInput } from "preline/preline";

@olegpix
Copy link
Collaborator

olegpix commented Jul 11, 2024

Summary

Preline 2.3.0 throws Module Parsed Failed if I tried to call HSPinInput.getInstance()

Steps to Reproduce

I'm trying to get the pin input object using HSPinInput.getInstance in NextJS, but got the following error for Preline 2.3.0.

Module parse failed: Unexpected token (22:21)
| 
| class HSAccordion
> 	extends HSBasePlugin<IAccordionOptions>
| 	implements IAccordion
| {

I'm not sure if I'm doing it in the right way to get the pin item instance object, because I got a different error in older version of Preline (e.g. 2.0.3 from the demo Stackblitz) which basically returns me a null object. What is the best way to get the pin value in this case?

Demo Link

https://stackblitz.com/edit/preline-v2-nextjs-tvm16z?file=src%2Fapp%2Fcomponents%2FPinInputItem.tsx

Expected Behavior

No response

Actual Behavior

No response

Screenshots

No response

Hi,
Please follow these steps:

  1. PrelineScript.tsx. You need to add the following code (check the full code in demo)
window.dispatchEvent(new CustomEvent('PrelineReady'));
  1. PinInputItem.tsx. You need to add the following code (check the full code in demo)
import type { HSPinInput } from 'preline';

declare global {
  interface Window {
    HSPinInput: typeof HSPinInput;
  }
}

...

useEffect(() => {
  const handlePrelineReady = () => {
    if (pinInputRef.current) {
      console.log(window.HSPinInput.getInstance(pinInputRef.current, true));
    }
  };

  window.addEventListener('PrelineReady', handlePrelineReady);

  return () => window.removeEventListener('PrelineReady', handlePrelineReady);
}, []);

In the future we will try to make this process easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants