score:0
your gallery is an array & you're trying to access it like an object. try this render method instead:
render() {
.....
if (this.state.buttonclicked) {
this.state.galerie.length > 0 ? console.log('=>', this.state.gallery!.album.id) : ''; //it should work now
}
......
}
score:3
you define state
but you don't specify it's type. typescript will thus infer the type of state
based on the initialization. since galerie
is an array but has no elements the best and safest type typescript can infer is never[]
the solution is to annotate the state
member:
class app extends react.component {
state:state = {
isloading: false,
errormsg: '',
buttonclicked: false,
jsonfromserver: "",
gallery:[]
}
//...
}
Source: stackoverflow.com
Related Query
- Property 'replace' does not exist on type 'IData'. What is missing?
- Property does not exist on type 'never[], What is wrong?
- Property 'value' does not exist on type 'Readonly<{}>'
- TypeScript error: Property 'X' does not exist on type 'Window'
- typescript + react/redux: property "yyy" does not exist on type 'intrinsicattributes & intrinsicclassattributes
- Typescript complains Property does not exist on type 'JSX.IntrinsicElements' when using React.createClass?
- error TS2339: Property 'for' does not exist on type 'HTMLProps<HTMLLabelElement>'
- TypeScript error after upgrading version 4 useParams () from react-router-dom Property 'sumParams' does not exist on type '{}'
- Property 'exact' does not exist on type
- Property 'toBeInTheDocument' does not exist on type 'Matchers<any>'
- Trigger click in Typescript - Property 'click' does not exist on type 'Element'
- Property does not exist on type 'DetailedHTMLProps, HTMLDivElement>' with React 16
- TS2339: Property 'tsReducer' does not exist on type 'DefaultRootState'
- Property ... does not exist on type 'IntrinsicAttributes & ...'
- Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'
- Property 'hot' does not exist on type 'NodeModule'.ts(2339)
- TS2339: Property 'props' does not exist on type 'Home'
- TypeScript error: Property 'children' does not exist on type 'ReactNode'
- TypeScript error: Property 'scrollIntoView' does not exist on type 'never'. TS2339
- Property 'value' does not exist on type 'never'. when use useRef hook in mui
- ts(2322) Property children does not exist on type 'Intrinsic attributes and Props'
- Property does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'
- Generics error with forwardRef: Property 'ref' does not exist on type 'IntrinsicAttributes'
- Property 'current' does not exist on type '((instance: HTMLDivElement | null) => void) | RefObject<HTMLDivElement>'
- In ReactJS trying to get params but I get property 'id' does not exist on type '{}'
- Property "value" does not exist on type Readonly
- Typescript Error: TS2339: Property 'span' does not exist on type 'JSX.IntrinsicElements'
- ReactJS TS, Property 'match' does not exist on type 'Readonly<{children?:ReactNode}> & Readonly<MyProps>'
- useRef Typescript error: Property 'current' does not exist on type 'HTMLElement'
- React with Typescript: Property 'push' does not exist on type 'History'
More Query from same tag
- Connecting Redux devtools and Thunk middleware to store
- React setState called before the ending of an async function
- React prop function called after useState set hook kills hook
- Webpack: Unknown property "query"?
- React - How to change className by index?
- How to change the dropdown value in Print dialogue box?
- React hooks useInterval reset after button click
- GatsbyJS & Netlify forms custom subject for form email notifications
- Webpack, React, JSX, Babel - Unexpected token <
- Cannot subscribe react-redux state in reactotron on ubuntu
- suneditor-react Typescript getContent is not working
- prevent multiple posts in react/mongoose
- How can I 'not allow' the user to retrieve same information from the server multiple times in my 'React' Weather-app?
- Jest fails with 'self is not defined' when importing react-diagrams
- Redux Reducer State Not Updating Properly
- for each car click I need to show the car name in the browser
- Reactjs - Get Height of a div/image using React Hooks
- Centering inner text, and text inside my circles
- What is state in React?
- How to run front end and back end in same port to deploy in tomcat server?
- Enable CORS in springboot mail API
- disabling button on specific condition on r
- ThreeJS different shapes object texture not working true
- React, page is refreshing constantly
- handle useReducer if pass from props
- jQuery-Like Way to Find / Select Array of React Elements
- Running Javascript to load a certain component based on switch statement from within JSX
- Optionally pass parameter to function being passed around
- How to replace the pattern in string with other string using react and regular expression?
- How to make rating stars in react js?