dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

$dispatch is not a function error #199

Closed sdpollack closed 5 years ago

sdpollack commented 5 years ago

I'm using dotNetify with use-netify and React hooks. I am receiving client updates fine, but now I'm trying to add updates to the server and I'm getting "TypeError: vm.$dispatch is not a function" error.

Here is some of the code:


import React, { Fragment } from 'react'
...
import dotnetify  from "dotnetify";
import useDotnetify from "use-dotnetify";

const unitList = require('../FakeData/FakeUnits.json')

  const [values, setValues] = React.useState({
    myVar: 'myvalue',
  })

  function handleChange(event) {
    setValues((oldValues) => ({
      ...oldValues,
      [event.target.name]: event.target.value,
    }))
    vm.$dispatch(values);
  }

  const initialState = {
    myVar: '',
    AssetViewData: [],
    unitName: "",
  };

  const vm = useDotnetify("myVMController", initialState);

...

  <form className={classes.root} autoComplete='off'>
    <FormControl className={classes.formControl}>
      <InputLabel ref={inputLabel} shrink htmlFor='unit-label-placeholder'>
        Unit
      </InputLabel>
      <Select
        value={values.unitName}
        key={values.unitId}
        onChange={handleChange}
        displayEmpty
        input={<Input name='unitName' id='unit-label-placeholder' />}
        name='unitName'
        className={classes.selectEmpty}
      >
        {unitList.map((units) => (
          <MenuItem value={units.unitName}>{units.unitName}</MenuItem>
        ))}
      </Select>
    </FormControl>
  </form>
dsuryd commented 5 years ago

const vm = useDotnetify("myVMController", initialState);

That function may not return the vm object. I'm not the maintainer of that library, either you raise an issue/PR with them, or fork and fix their code.

sdpollack commented 5 years ago

Do you have any plans to support React Hooks directly in dotNetify?

dsuryd commented 5 years ago

I do, no time frame, but PR is welcome if you want to make it happen sooner. I'm closing this issue as 'not dotNetify bug'. Let's use #177 to track React hook support.

sdpollack commented 5 years ago

Thanks for your fast response. I'm a very novice developer and I fear submitting a PR is over my head.