Giter Club home page Giter Club logo

Comments (5)

aintHuman avatar aintHuman commented on June 15, 2024

Or alternatively, you could include your own useEffect hook to detect changes to initial value, which would probably be more optimal.

from react-pin-input.

aintHuman avatar aintHuman commented on June 15, 2024

For anyone else that needs to do something like this, after reviewing the source code, this is the solution I came up with:

    React.useEffect(() => {
        if(ref && ref?.current){
            const valueArr = (value || '').toString().split('');

            // No changes necessary, short circuit.
            if(isEqual(valueArr, ref.current.values))
                return; 

            // Iterate over each digit updating from valueArray item
            for(let i = 0; i < ref.current.elements.length; i++){
                ref.current.elements[i].update(valueArr[i] || '', true);
            }
        }
    },[value])

Not sure if its what the maintainer would have recommended, but it works for me.

from react-pin-input.

arunghosh avatar arunghosh commented on June 15, 2024

@aintHuman Thank you for the suggestion and solution. Will look into this.

from react-pin-input.

aintHuman avatar aintHuman commented on June 15, 2024

Also, can you expose the onFocus / onBlur callbacks as arguments in the constructor (which get passed down to each PinItem, and called after your own internal usage), so that I can detect from my parent component, when an individual field has been entered / left.

I need this for a touchpad where there is no keyboard and therefore need to have a up/down button to step the value up / down, or make a keypad to enter the values by touch.

from react-pin-input.

arunghosh avatar arunghosh commented on June 15, 2024

@aintHuman Sure. Will consider.

from react-pin-input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.