使用“react-router-dom”:“^5.2.0”和“react”:“16.8.6”,
我有这个:
<Switch>
<Route path="/users" component={Users} />
<Route path="/users/:id" component={Users} />
</Switch>
Run Code Online (Sandbox Code Playgroud)
并在用户组件中:
const param = useParams();
console.log(param);
Run Code Online (Sandbox Code Playgroud)
因此,如果我输入/users或/users/10始终将参数呈现为空对象。我在这里缺少什么?
我正在使用jest进行测试.我正在使用react和redux,我有这个动作:
function getData(id, notify) {
return (dispatch, ...) => {
dispatch(anotherFunction());
Promise.all(['resource1', 'resource2', 'resource3'])
.then(([response1,response2,response3]) => {
... handle responses
})
.catch(error => { dispatch(handleError(error)); }
};
}
Run Code Online (Sandbox Code Playgroud)
我一直在寻找如何为此操作设置测试的jest文档,但我无法找到方法.我尝试过这样的事情:
it('test description', (done) => {
const expectedActions = [{type: {...}, payload: {...}},{type: {...}, payload: {...}},...];
fetchMock.get('resource1', ...);
fetchMock.get('resource2', ...);
fetchMock.get('resource3', ...);
... then the rest of the test calls
});
Run Code Online (Sandbox Code Playgroud)
不成功.那我该怎么办呢?
我正在构建一个软件,它从用户那里获取整数并进行一些计算,然后输出结果。问题是我想使用英语数字获取用户数字(0, 1, 2, etc.),并且我想在输出中使用波斯数字(如阿拉伯语)显示数字。我已经阅读了一些有关 Unicode 转换的主题以及诸如replace()和 之类的内容charCodeAt(),但我无法理解代码。
这是一段代码。(它将波斯数字转换为英文数字,但我想做相反的事情。)
\n\n var yas ="\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xa4\xd9\xa5\xd9\xa6\xd9\xa7\xd9\xa8\xd9\xa9";\n yas = Number(yas.replace(/[\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xa4\xd9\xa5\xd9\xa6\xd9\xa7\xd9\xa8\xd9\xa9]/g, function (d) {\n return d.charCodeAt(0) - 1632; \n }).replace(/[\xdb\xb0\xdb\xb1\xdb\xb2\xdb\xb3\xdb\xb4\xdb\xb5\xdb\xb6\xdb\xb7\xdb\xb8\xdb\xb9]/g, function (d) { return d.charCodeAt(0) - 1776; })\n );\nRun Code Online (Sandbox Code Playgroud)\n 我正在使用 webpack 4 并且我安装了一个包含很多子文件夹的模块,结构是:
/node_modules/my_main_package/what_i_need_to_include
我需要排除整个node_modules除了what_i_need_to_include. 这是我webpack.base.babel迄今为止尝试过的:
第一种方法:
module: {
rules: [
{
test: /\.js$/,
exclude: '/node_modules/',
include: '/node_modules/my_main_package/what_i_need_to_include',
use: {
loader: 'babel-loader',
options: options.babelQuery,
},
},
...
Run Code Online (Sandbox Code Playgroud)
第二种方法:
{
test: /\.js$/,
exclude: '/node_modules\/(?!my_main_package/what_i_need_to_include).*/'
...
}
Run Code Online (Sandbox Code Playgroud)
两次都没有成功。
我怎样才能让它工作?我究竟做错了什么?
我有一个 spring-boot 应用程序,我用它Prometheus来收集指标数据。Prometheus 有一些指标,例如Counter可以很好地计算某事发生的次数,Gauge它也可以保持计数,但可以减少等等。是否有一个指标可以让我跟踪某事的请求持续时间?例如,假设我想记录在进行 api 调用和 api 返回响应之间所花费的时间。我将如何跟踪进行调用和收到 api 响应之间的时间?然后,是否可以在Y坐标上创建一个图表,我可以列出响应所花费的时间长度(以秒或毫秒为单位);然后在X 轴,是否显示时间戳(收集指标的时间)?
我很新的阵营挂钩,我想更换connect,mapStateToProps等等带useSelector,useDispatch。这就是我所拥有的:
import React from 'react';
import { useSelector } from 'react-redux';
function MyComponent(props) {
const data = useSelector(state => state.app.loadingData);
return (
<div>
{data}
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
其中,根据https://react-redux.js.org/api/hooks写得很好。这是我的 Redux DevTools 控制台:
因此,app存在于 redux 状态树中并且也loadingData存在。无论如何,我的浏览器控制台指向const data = useSelector(state => state.app.loadingData);大喊我有这个错误:
未捕获的类型错误:Object(...) 不是函数
那么,我做错了什么或者我在这里错过了什么?
我有一个呈现图像的React组件.该图像必须捕获onClick事件,但事实并非如此.这种行为没有理由.这是代码:
class MyComponent extends React.Component {
imageClick = () => {
console.log('Click!!!!');
}
render () {
return (
<div>
<img src='/myfolder/myimage.png' onClick={this.imageClick} />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它没有显示我回来'点击!!!!' 单击图像时,浏览器控制台中的消息.它给了我没有错误,没有警告,没有任何东西.我正在使用在Linux Mint上运行的Chrome 62.0.3202.
当它被隔离时这个代码可以工作,但是在样板文件中却没有,这就是我的情况.
我在这里错过了什么?
我正在尝试将时间戳转换为 moment js 对象,如下所示:
let obj = moment.unix(1459382400);
Run Code Online (Sandbox Code Playgroud)
它返回 Wed Mar 30 2016 20:00:00 GMT-0400 (CDT) 这是错误的,因为给定的时间戳对应于 Thu, 31 Mar 2016 00:00:00 GMT。
我错过了什么吗?我究竟做错了什么?
我正在创建一个程序,允许用户与输入的文件进行交互.其中一个选项是显示文件.下面,我首先通过创建由线组成的arraylists,然后是由空格分隔的字符串分隔的内部arraylist,将文件存储到arraylist中.
Scanner sc = new Scanner(fileName);
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] words = {};
words = line.split(" ");
ArrayList<String> lineArray = new ArrayList<String>();
for (int i = 0; i < words.length; i++) {
lineArray.add(words[i]);
}
fileByLine.add(lineArray);
}
sc.close();
Run Code Online (Sandbox Code Playgroud)
我正在尝试打印arraylist的内容,称为fileByLine,因为它们出现在文件中,但我不知道如何.有什么建议吗?
case '1':
for(int i = 0; i < fileByLine.size(); i++){
for(int j = 0; j < fileByLine.[i].size(); j++){
System.out.print(fileByLine[i][j]);
} System.out.println("");
} break;
Run Code Online (Sandbox Code Playgroud) 我需要以 MM/dd/yyyy, hh:mm tt 格式显示“en”和“es”区域设置的日期。这种方法工作正常,但它将日期显示为 MM/dd/yy,仅显示年份的最后两位数字,而不是条目年份。
const en = new Intl.DateTimeFormat('en', { dateStyle: 'short', timeStyle: 'short', hour12: true }).format(new Date());
const es = new Intl.DateTimeFormat('es', { dateStyle: 'short', timeStyle: 'short', hour12: true }).format(new Date());
console.log('En', en, 'Es', es);Run Code Online (Sandbox Code Playgroud)
这种方法
const en = (new Date()).toLocaleString('en');
const es = (new Date()).toLocaleString('es');
console.log('En', en, 'Es', es);Run Code Online (Sandbox Code Playgroud)
显示全年,但显示“es”区域设置的 24 小时格式。
从这里我知道,当格式化大量日期时,最好创建一个 Intl.DateTimeFormat 对象并使用其 format 属性提供的函数。情况可能就是这样。我怎样才能让它发挥作用?
我有一个Generic方法smallestValueInArray(T[] array),这个方法得到一个任何类型的数组.此方法如下所示:
public class Helper {
public static <T extends Comparable<T>> T smallestValueInArray(T[] array) {
T smallestValue = array[0];
T smallerTempValue = array[0];
for (int i = 0; i < array.length - 2; i+=2) {
if (array[i].compareTo(array[i+1]) < 0) {
smallerTempValue = array[i];
} else {
smallerTempValue = array[i+1];
}
if (smallestValue.compareTo(smallerTempValue) > 0) {
smallestValue = smallerTempValue;
}
}
return smallestValue;
}
}
Run Code Online (Sandbox Code Playgroud)
在Main方法中我想做这样的事情:
for (int i = 0; i < stringArray.length; i++) {
someOtherArray[i] = Helper.smallestValueInArray(stringArray); …Run Code Online (Sandbox Code Playgroud) javascript ×5
reactjs ×4
java ×3
arraylist ×1
arrays ×1
datetime ×1
events ×1
format ×1
grafana ×1
iteration ×1
jestjs ×1
material-ui ×1
momentjs ×1
monitoring ×1
onclick ×1
prometheus ×1
react-hooks ×1
react-redux ×1
react-router ×1
redux ×1
string ×1
testing ×1
unicode ×1
webpack ×1