react-hot-loader v4,哪里应该很热?

时间:2018-02-12 05:22:19

标签: redux react-hot-loader

我有两个组件,App和Root。 应用程序有路由,并提供常见的布局。

const App = () => (
  <Layout>
    <Routes />
  </Layout>
)

const Root = () => (
  <Providers>
    <App />
  </Providers>
)

虽然Providers包含redux&#39; Provider,redux-persist&#39; PersistGate和react-router-redux&#39; ConnectedRouter

所以,我的主要问题是

  1. 我应该把hot(module)(Component)帮助者放在哪里?在App?还是Root
  2. 这些是AppContainer API。

    1. hot助手和AppContainer之间的区别是什么?是否有AppContainerhot更适合的特殊情况?

1 个答案:

答案 0 :(得分:0)

AppContainer vs hot

  

在v4之前,设置React Hot Loader的正确方法是包装你的   Application AppContainer// App.js import React from 'react' import { hot } from 'react-hot-loader' const App = () => <div>Hello world!</div> export default hot(module)(App) ,设置接受设置模块   你自己。这种方法仍然有效,但仅限于高级用途   案件,更喜欢使用热帮手。

React Hot Loader v4:

// main.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './containers/App'

ReactDOM.render(<App />, document.getElementById('root'))
public class Hotel
{
    private HashSet<int> avalibe;
    private HashSet<int> busy;


    //constructor to set number of rooms
    public Hotel(int totalNumberOfRooms)
    {
        avalibe = new HashSet<int>();
        for (int i = 1; i <= totalNumberOfRooms; i++)
            avalibe.Add(i);
        busy = new HashSet<int>();
    }

    //Returns true if room is available
    public bool hasRoomsAvailable()
    {
        return avalibe.Count > 0;
    }
    //Time Complexity: O(1)

    //Checks if there's at least one room available and it reserves it
    public int checkIn()
    {
        if (hasRoomsAvailable())
        {
            var result = avalibe.First();
            avalibe.Remove(result);
            busy.Add(result);
            return result;
        }
        else
            return -1;
    }
    //Time Complexity: O(1)

    //Check out method
    public void checkOut(int roomNumber)
    {
        if (!busy.Contains(roomNumber))
        {
            Console.WriteLine("Incorrect room number : {0}", roomNumber);
            return;
        }
        busy.Remove(roomNumber);
        avalibe.Add(roomNumber);
    }


}

我应该把热(模块)(组件)助手放在哪里?在应用程序?还是在Root?

你应该让你的应用程序变热,因为你很少会编辑你的根组件, 但是应用内的内容会经常更新。