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

TypeError: Attempted to assign to readonly property #92

Closed
wizevlad opened this issue Mar 9, 2020 · 11 comments
Closed

TypeError: Attempted to assign to readonly property #92

wizevlad opened this issue Mar 9, 2020 · 11 comments
Labels
bug Something isn't working cant reproduce Elaboration on how to reproduce the issue is needed more info required

Comments

@wizevlad
Copy link

wizevlad commented Mar 9, 2020

Code:

try {
  let whyDidYouRender = require('@welldone-software/why-did-you-render')
  let ReactRedux = require('react-redux')
  whyDidYouRender(React, {
    trackAllPureComponents: true,
    trackExtraHooks: [[ReactRedux, 'useSelector']]
  })
} catch (error) {
  console.warn(error)
}

Error: TypeError: Attempted to assign to readonly property

Screen Shot 2020-03-09 at 5 23 44 PM

@wizevlad
Copy link
Author

wizevlad commented Mar 9, 2020

It's worth mentioning that without the options, the error doesn't appear, but it seems that the library doesn't work either.

@vzaidman
Copy link
Collaborator

what is the "t" component, do you know?
what versions are you using?
where do you execute the code?

@wizevlad
Copy link
Author

The t function is a hook to perform i18n:

const getTranslate = translations => (key, ...params) => {
  let value = translations[key] || key
  if (params) {
    params.forEach((p, idx) => {
      value = value.replace(`{${idx}}`, p)
    })
  }
  return value
}

export const useI18n = () => {
  const language = useSelector(state => state.language)
  const { locale = 'en' } = language
  return useMemo(() => getTranslate(languages[locale]), [locale])
}

React 16.12

Component Example:

function Home({ animationState }) {
  const t = useI18n()
  const dispatch = useDispatch()
  const history = useHistory()

  const isFetching = useSelector(state => state.site.isFetching)
  const sites = useSelector(state => state.site.sites || [])
  const error = useSelector(state => state.site.error)

  const found = length(sites) || 0
  const errorMessage = path(['data', 'message'], error)

  useEffect(() => {
    if (animationState === 'enter') dispatch(GET_SITES_INIT())
  }, [dispatch, animationState])

  const notFoundText = t('NOT_FOUND')

  const filterSites = (inputValue, cb) => {
    // ...
  }

  return (
    <section className="home is-flex has-text-centered full-height">
      <div className="section">
        <span className="sp sp-map has-text-white" />
        <h6 className="is-uppercase mt-20 mb-20">{t('SELECT_SITE')}</h6>

        <SearchField
          onSearch={filterSites}
          onSelect={compose(setSite(history, dispatch), prop('site'))}
          notFoundText={notFoundText}
        />

        <div className="message mb-10 mt-10">
          <p className="pl-20 pr-20">
            {isFetching ? t('FETCHING_SITES') : t('FOUND_SITES', found)}
          </p>
        </div>

        {either(
          error,
          <div className="message error mb-10 mt-10">
            <p className="pl-20 pr-20"> {t('FETCH_SITE_ERROR')} </p>
            <p className="pl-20 pr-20"> {errorMessage} </p>
          </div>
        )}
      </div>
      <section>
        <p>{t('CS_NOT_FOUND')}</p>
        <Link
          to={paths.PROTECTED.CREATE_SITE.path}
          className="link is-uppercase"
        >
          <small>{t('CREATE_SITE')}</small>
        </Link>
      </section>
    </section>
  )
}

@vzaidman
Copy link
Collaborator

ok looks like there's something weird with i18 indeed, i'll check it out

@vzaidman vzaidman added the bug Something isn't working label Mar 10, 2020
@technikhil314
Copy link

technikhil314 commented Mar 27, 2020

I am using react-redux version "2.3.0" looks like its not able to keep track of useSelector hook. It fails with error as TypeError: Cannot set property useSelector of #<Object> which has only a getter

@vzaidman
Copy link
Collaborator

I am using react-redux version "2.3.0" looks like its not able to keep track of useSelector hook. It fails with error as TypeError: Cannot set property useSelector of #<Object> which has only a getter

this comment is not related to the bug.
your bug is #85

@technikhil314
Copy link

Ok thanks @vzaidman Got it.

@vzaidman
Copy link
Collaborator

@wizevlad can you please update all the related libraries and check again? I don't seem to see any problem

@vzaidman vzaidman changed the title Error setting up the library TypeError: Attempted to assign to readonly property Apr 24, 2020
@vzaidman vzaidman added cant reproduce Elaboration on how to reproduce the issue is needed more info required labels Apr 24, 2020
@vzaidman
Copy link
Collaborator

You are free to re-open the bug once you can provide more information

@wizevlad
Copy link
Author

I have react-redux v7.2.0. and why-did-you-render v4.2.0. Got this error:

Screen Shot 2020-05-11 at 12 48 55 PM

Readable:

error: TypeError: Super expression must either be null or a function

@vzaidman
Copy link
Collaborator

@wizevlad
this is another issue. moved to #118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cant reproduce Elaboration on how to reproduce the issue is needed more info required
Projects
None yet
Development

No branches or pull requests

3 participants