SolidJSS
SolidJSโ€ข2y agoโ€ข
3 replies
Rinma

How to get snapshot value from store

Hi,
I currently have the following problem. I try to create a file and need values from a Store for this. Here some code:

The store state/list-state.js
import { createStore } from 'solid-js/store';

const [listState, setListState] = createStore({
  list: [],
});

export const useListState = () => [listState, setListState];


A button components/Actions.jsx
import styles from './Actions.module.css';
import { parseFile } from '../../utils/file';
import { useListState } from '../../state/list-state';

export default function Actions() {
  const [listState] = useListState();

  function startParsing() {
    parseFile(listState.list);
  }

  return (
    <div
      class={styles.actions}
      onClick={() => {
        startParsing();
      }}
    >
      <h1>Generate List</h1>
    </div>
  );
}


The file parser utils/file.js
export function parseFile(list) {
  console.log(list);
  console.log(list?.forEach((entry) => entry));

  const today = new Date();
  const file = `
  {
    ${list?.forEach((entry, index) => `entry: "${entry.url}`)}
  }`;
}


The problem now is, that parseFile(listState.list); ends in me getting a Proxy object, that is what my browser console is reporting, instead of the wanted array list. When I try to access it, I only get undefined back. And now I don't understand how to get something like a non-reactive snapshot of the value from the store object, that I can use as a parameter for the parse function. Or what is happening here, why is it undefined ๐Ÿ˜ตโ€๐Ÿ’ซ
Was this page helpful?