Text-mask: Style component, TypeError: Cannot read property 'value' of undefined

Created on 9 Oct 2019  路  3Comments  路  Source: text-mask/text-mask

I tried to use style component and gets this error:

pic

This is simple create react app code:

import React from "react";
import MaskedInput from 'react-text-mask';
import styled from 'styled-components';
import createAutoCorrectedDatePipe from 'text-mask-addons/dist/createAutoCorrectedDatePipe'

const MyStyledInput = styled.input`
  background: red;
`;

function App() {

  const autoCorrectedDatePipe = createAutoCorrectedDatePipe('dd/mm/yyyy');
  return <div className="App">
    <MaskedInput
      mask={[/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/]}
      placeholder={'DD/MM/YYYY'}
      pipe={autoCorrectedDatePipe}
      guide={true}
      keepCharPositions={true}
      render={(ref, props) => (
        <MyStyledInput innerRef={ref} {...props} />
      )}
    />
  </div>;
}

export default App;

full code here:
https://github.com/kenpeter/radio-button/tree/auto-date

Most helpful comment

same issue :-( ... I have no idea how to fix it

<MaskedInput 
mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]} 
placeholder="Enter a phone number" 
id="my-input-id" 
render={(ref, props) => <MyStyledInput ref={ref} {...props} />} 
/>

const MyStyledInput = styled.input`
  background: papayawhip;
`;

NOTE: using ref={ref} not innerRef={ref}

All 3 comments

Did you manage to fix the issue? I'm having the same problem.

same issue :-( ... I have no idea how to fix it

same issue :-( ... I have no idea how to fix it

<MaskedInput 
mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]} 
placeholder="Enter a phone number" 
id="my-input-id" 
render={(ref, props) => <MyStyledInput ref={ref} {...props} />} 
/>

const MyStyledInput = styled.input`
  background: papayawhip;
`;

NOTE: using ref={ref} not innerRef={ref}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

msafi picture msafi  路  7Comments

caub picture caub  路  4Comments

gabrielamarques picture gabrielamarques  路  6Comments

KevinGruber picture KevinGruber  路  6Comments

refo picture refo  路  6Comments