I am trying to use a Record<TableId, TableState>
object where type TableId = string;
. However, when I go to print out the contents of the record object after setting the key/value pair via setTableStateMap(map)
... I get back the object {id: {…}}
instead of the value I passed to the 'id' variable.
// App.tsx---------------------------------------
React.useEffect(() => {
setCallback((id: TableId, tableState: TableState) => {
const map: Record<TableId, TableState> = { id: tableState };
setTableStateMap(map);
});
// Table Component-------------------------------
type TableId = string;
type Callback = (id: TableId, state: TableState) => void;
let callback: Callback;
export function setCallback(callbackInput: Callback) {
callback = callbackInput;
}
let stateMap: Record<TableId, TableState> = {};
export function setTableStateMap(map: Record<TableId, TableState>) {
stateMap = map;
}
interface TableProps {
id?: TableId;
}
export const Table: React.FC<TableProps> = ({
id,
}) => {
let tableState: TableState | undefined;
if (id) {
tableState = stateMap[id];
// stateMap has key set to 'id' and not value of variable id
// {id: {…}}
} else {
tableState = undefined;
}
};