score:7
the first issue can be solved with a null check before proceeding with your logic since react.createref()
can also return null
:
componentdidmount() {
if(this.circleref !== null && this.circleref.current !== null) {
this.circleref.current.setnativeprops({
someproperty: somevalue
});
}
}
the second is solved by passing the class name of the node element for which you want to create a reference. for example, if your referenced element is a <text>
, then do:
circleref = react.createref<text>();
this way, circleref
will be correctly typed and setnativeprops
will exist if and only if the referenced component is directly backed by a native view:
the methods [of
current
] are available on most of the default components provided by react native. note, however, that they are not available on composite components that aren't directly backed by a native view. this will generally include most components that you define in your own app. - direct manipulation - react native documentation
score:7
you can add typescript typings to a react native ref like this:
const textinputref: react.refobject<textinput> = react.createref();
Source: stackoverflow.com
Related Query
- How to use forwardRef with FunctionComponent in React Native using TypeScript
- Using state in react with TypeScript
- React with Typescript -- Generics while using React.forwardRef
- Using React forwardRef with Typescript generic JSX arguments
- Proper way of using WebSockets with React Native
- Error : Cannot read property fetch. Using jest-expo with react native
- react native post form data with object and file in it using axios
- Something went wrong with react table using typescript
- create timer with react native using es6
- How to use jest.spyOn with React function component using Typescript
- Using react context with react hooks in typescript
- Connecting a component with OwnProps using react redux and typescript in the .NET Core 2.0 reactredux template project
- can i use the tsx extension for test files if using react with typescript
- this.props.yyy is undefined while using react with typescript but working properly in es5?
- Is it possible to type a React function component with TypeScript without using arrow functions?
- Jest test for a copy to clipboard method using react with typescript
- Refresh Screen A when goBack with React Native using Hooks
- Why do I need to do export const useAppDispatch = () => useDispatch<AppDispatch>() when using Typescript with React
- How to User Login With Wordpress using React Native
- Using typescript with useRoute on react navigation v5
- Remove Event Handler using Abort Signal with Typescript and React
- How to set up a chrome extension using React and TypeScript with multiple pages and entry points?
- Using TypeScript with React HOC, React.lazy and forwarRef
- Test suits failed with "SyntaxError: Unexpected token 'export" ' react typescript using jest
- Property does not exist on state - Using React Router Hooks with TypeScript
- React with TypeScript using tsyringe for dependency injection
- Error using css modules in typescript react with webpack config
- Disadvantages of making all TypeScript in a project using React with .tsx
- Using Socket.io with typescript and react
- React Memory Leakage with typescript using google firestore and react router
More Query from same tag
- Update array object in React Redux reducer
- Checked Items is undefined on selection React JS
- Redux store can not get state from reducer
- Loading font native-base error
- How to format \n as a line break in my markdown returned via a GraphQL query
- Adding props to constructor as this.prop
- How to conditionally render a component from the property of a constant in React?
- How can I use setInterval() to automatically change slides on this React Spring project
- What is best approach to responsive buttons with icons in material-ui?
- vite react dynamic image url
- Ag grid to put border only between group values
- React: add route with mandatory query string
- Sharing on React JS Mobile application
- How to disable content when sidebar is opened?
- Test React component method is calling function pass as a prop
- sorting different types of variables in an array
- Creating styled url for finished react app
- How to preview an image using react-dropzone
- what is the best way to show some piece of code or snippet in component template using ReactJS App?
- text and icon in a antd button are not aligned vertically
- react - react router - privateRoute - infinite loop
- Uploading files in react by react-dropzone and formik
- What is the type of a styled-component's argument(s)?
- Changing Autocomplete value using react-hook-form (Material-UI)
- Add/inject React component into pure HTML that came from the back-end
- Why are React components executed through the `React.createElement()` method?
- TypeError: Cannot read property 'subscribe' of undefined PersistGate.componentDidMount
- Updating values inside an object as soon as other array changes in Javascript React
- Is there a way to externally reset a react component to its original state
- Add google trends in react