A
A
Anton Kucherov2017-03-27 14:47:55
JavaScript
Anton Kucherov, 2017-03-27 14:47:55

Is it possible to get initialState from DOM when using Flux?

I am using flux.utils . You need to get a CSRF token for the form. It comes to me from the server and goes
into the meta tag. The question is, is it correct to get it when initializing `Store`, something like this:

class SomethingStore extends ReduceStore {
  constructor() {
    super(Dispatcher);
  }

  getInitialState() {
    return Map({
      value: '',
      csrf: document.querySelector("meta[name=csrf-token]").content,
    });
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-03-27
@AppFA

Somehow it doesn't look very nice. Is there no way to get this token via API? Well, or as an option when rendering the page, do this:

<script>
    window.__CSRF__ = 'token';
</script>

And already from window.__CSRF__ in the application to get this token

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question