dsuryd / dotNetify

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

import {Scope} from 'dotnetify/react'; #207

Closed martijnenco closed 5 years ago

martijnenco commented 5 years ago

How do I use the <Scope ... /> component? If I try to import it I get an error saying: Module not found: Can't resolve 'dotnetify/react' As far as I know I use it exactly the same as in http://dotnetify.net/core/examples/compositeview

Here is my code:

import 'bootstrap/dist/css/bootstrap.css';
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import dotnetify from "dotnetify";
import {Scope} from 'dotnetify/react';

const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href');
const rootElement = document.getElementById('root');
dotnetify.debug = true;

ReactDOM.render(
  <BrowserRouter basename={baseUrl}>
    <Scope vm="App">
      <App/>
    </Scope>
  </BrowserRouter>,
  rootElement);

registerServiceWorker();

And further down in there are some other scopes. But currently, it's crashing on the import...

dsuryd commented 5 years ago

Apparently documentation error; should be: import dotnetify, { Scope } from "dotnetify";

martijnenco commented 5 years ago

Thank you for the quick answer! Alright, now I did that but now I have the next error(s). My IDE is saying that it can't resolve 'Scope'. It looks like Scope didn't do what I expected since I still get the error: TypeError: this.vm.$destroy is not a function. Is there something else I do wrong?

dsuryd commented 5 years ago

Perhaps it'll be easier with reference implementation, so I added a simple Composite View example with 'Scope' to the React SPA demo here: https://github.com/dsuryd/dotNetify/tree/master/Demo/React/SPA

Let me know if you stil run into problems.