I am using React-TypeScript for my project. For state management, I am using React-redux, for function handling I am using redux-saga. For gluing the redux store and functions I am using React's new hooks useSelector
and useDispatch
. I successfully pull the data and able to show it in the console.My data looks like this. Based on useSelector documentation I can able render the useSelector
without passing to the state. When I am mapping the useSelector
's variable I am getting TypeScript error: Object is of type 'unknown'
. PS. I am new in TypeScript as well.
This is my React functional component
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import ErrorBoundary from 'components/errorBoundary';
import { useDispatch, useSelector } from 'react-redux';
import { IPropertiesList } from '../../state/properties/types';
import { fetchProperties } from '../../state/properties/actions';
import { IIssueListItem } from '../../state/issues/types'
import { fetchIssuesList } from '../../state/issues/actions'
import list from '../issues/list';
export interface ITestNewListProps {
className?: string;
}
const Test = ({ className }: ITestNewListProps) => {
const dispatch = useDispatch();
const properties = useSelector<IPropertiesList | undefined>(
(state: any) => state.properties.list.data
);
const issues = useSelector<IIssueListItem | undefined>(
(state: any) => state.issues.list.data
)
useEffect(() => {
// fetch the properties data from the api if we don't already have it
!properties && dispatch(fetchProperties({}));
}, [dispatch, properties]);
useEffect(() => {
!issues && dispatch(fetchIssuesList())
}, [dispatch, issues]);
console.log(`properties`, properties); //I can able to see the data
console.log(`issues`, issues);
return (
<ErrorBoundary id="TestNewListErrorBoundary">
<div className={`${className}`}>
{
properties.map(list => { // IN HERE I AM GETTING ERROR
return <div>{list.name}</div>
})
}
</div>
</ErrorBoundary>
);
};
Test.displayName = `Test`;
export default styled(Test)`
`;