How to use the dotnetify.useConnect function in dotnetify

To help you get started, we’ve selected a few dotnetify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dsuryd / dotNetify / Demo / React / SPA / client / SimpleList.js View on Github external
export default () => {
  const [ newName, setNewName ] = useState('');

  // Connect this component to the back-end view model.
  const { vm, state } = useConnect('SimpleListVM', { Employees: [] });

  // Set up function to dispatch state to the back-end.
  const dispatch = state => vm.$dispatch(state);

  return (
    
      <header>
        <span>Add:</span>
         setNewName(value)}
          onUpdate={value =&gt; {
            dispatch({ Add: value });
            setNewName('');
          }}</header>
github dsuryd / dotNetify / DevApp / client / app / views / Overview.js View on Github external
const ServerUpdate = () =&gt; {
  const { vm, state } = useConnect('ServerUpdate', { Greetings: '' });
  const [ firstName, setFirstName ] = useState('');
  const [ lastName, setLastName ] = useState('');

  const handleFirstName = e =&gt; setFirstName(e.target.value);
  const handleLastName = e =&gt; setLastName(e.target.value);
  const handleSubmit = () =&gt; vm.$dispatch({ Submit: { FirstName: firstName, LastName: lastName } });
  return (
    <div>
      <div>{state.Greetings}</div>
      <input value="{firstName}" type="text">
      <input value="{lastName}" type="text">
      <button>Submit</button>
    </div>
  );
};
github dsuryd / dotNetify / Demo / React / SPA / client / App.js View on Github external
export default () =&gt; {
  const { vm, state } = useConnect('App', { Links: [] });
  if (vm) vm.onRouteEnter = (path, template) =&gt; (template.Target = 'Content');

  return (
    <div>
      <nav>
        {state.Links.map(link =&gt; (
          
            {link.Caption}
          
        ))}
      </nav>
      <div style="{{" id="Content">
    </div>
  );
};
</div>
github dsuryd / dotNetify / DevApp / client / app / views / Overview.js View on Github external
const RealTimePush = () =&gt; {
  const { state } = useConnect('RealTimePush', { Greetings: '', ServerTime: '' });
  return (
    <div>
      <p>{state.Greetings}</p>
      <p>Server time is: {state.ServerTime}</p>
    </div>
  );
};